groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MG <mg...@arscreat.com>
Subject Re: Omitting parentheses on .size() ?
Date Sat, 01 Aug 2020 17:41:44 GMT
Hmmm, I am for consistency, but at least I use very few maps as compared 
to lists, and rarely ever output the size of a map, but constantly for 
lists, so having getSize() on List would still be beneficial.

This has of course been discussed many times before - maybe a "size" 
operator:

#list // list.size()
#map // map.size()
#string // string.length

which people could override (e.g. sizeOf() method) and which unifies all 
kinds of "how many elements do I hold / how big am I" concepts (if its 
not a collection holding items) ?-)

Cheers,
mg


On 01/08/2020 18:08, OCsite wrote:
> MG,
>
>> On 1 Aug 2020, at 14:59, MG <mgbiz@arscreat.com 
>> <mailto:mgbiz@arscreat.com>> wrote:
>> What was the reason again Groovy does not add getSize() here... ?-)
>
> Consistency I guess. Having a List.size would lead to a request to add 
> Map.size, which alas would clash with Map['size'].
>
> All the best,
> OC
>
>> On 01/08/2020 04:06, Paul King wrote:
>>> What Daniel said is correct. Also if there was an accessible 
>>> getSize() method, you could use just ".size".
>>>
>>> Cheers, Paul.
>>>
>>> On Sat, Aug 1, 2020 at 11:19 AM Daniel Sun <sunlan@apache.org 
>>> <mailto:sunlan@apache.org>> wrote:
>>>
>>>
>>>     The parentheses of methods without parameters could not be ommitted.
>>>
>>>     `[1, 2, 3].size` is accessing the private field `size` of
>>>     `ArrayList`, so illegal reflective access warning will be thrown.
>>>
>>>     Cheers,
>>>     Daniel Sun
>>>     On 2020/08/01 00:49:54, paul <pl.gruener@gmail.com
>>>     <mailto:pl.gruener@gmail.com>> wrote:
>>>     > Hi all,
>>>     >
>>>     > (on latest groovy 3.0.5 and OpenJDK 14) omitting the empty
>>>     parentheses to the .size() call works, but throws an illegal
>>>     reflective access warning:
>>>     >
>>>     > ```
>>>     > groovy:000> [1,2,3].size
>>>     > WARNING: An illegal reflective access operation has occurred
>>>     > WARNING: Illegal reflective access by
>>>     org.codehaus.groovy.reflection.ReflectionUtils
>>>     (file:/home/paul/.sdkman/candidates/groovy/3.0.5/lib/groovy-3.0.5.jar)
>>>     to field java.util.ArrayList.size
>>>     > WARNING: Please consider reporting this to the maintainers of
>>>     org.codehaus.groovy.reflection.ReflectionUtils
>>>     > WARNING: Use --illegal-access=warn to enable warnings of
>>>     further illegal reflective access operations
>>>     > WARNING: All illegal access operations will be denied in a
>>>     future release
>>>     > ===> 3
>>>     > ```
>>>     >
>>>     > Curiously, the size() method seems to be the only
>>>     parameter-less method where I can
>>>     > omit the empty parentheses – all others throw a
>>>     MissingPropertyException (as expected).
>>>     >
>>>     > What is the desired behaviour, and why is it even working
>>>     (albeit with warnings) with .size ?
>>>     >
>>>     >
>>>     > best
>>>     > paul
>>>     > --
>>>     > typed with Neo 2 -- an ergonomically optimized keyboard layout
>>>     > for German, English, programming, and science
>>>     > ❤ http://neo-layout.org <http://neo-layout.org/>
>>>     > ❤ https://useplaintext.email <https://useplaintext.email/>
>>>     > ❤ YY-MM-DD dates (ISO 8601/RFC 3339)
>>>     > � UTF-8 encoding
>>>     >
>>>
>>
>


Mime
View raw message