While I was toying around with non-static inner classes I found this piece
of text in the Groovy documentation under the `Creating Instances of
Non-Static Inner Classes` section:
"Caution though, Groovy supports calling methods with one parameter without
giving an argument. The parameter will then have the value null. Basically
the same rules apply to calling a constructor. There is a danger that you
will write new X() instead of new X(this) for example. Since this might
also be the regular way we have not yet found a good way to prevent this
problem."
Just in case someone could come around the topic of this thread in the
future.
Cheers.
On Tue, Sep 1, 2015 at 1:46 AM, Edinson E. Padrón Urdaneta <
edinson.padron.urdaneta@gmail.com> wrote:
> Thank you, blackdrag. I always can count on you.
>
> Cheers.
>
> On Tue, Sep 1, 2015 at 1:39 AM, Jochen Theodorou <blackdrag@gmx.org>
> wrote:
>
>> you miss nothing. This is a logic I wanted to get rid of before Groovy
>> 1.0 already, but was said to be needed for some special constructs back
>> then. And now you cannot easily remove it. But the static compiler does not
>> support it, because in the longterm we want to get rid of it
>>
>> bye blackdrag
>>
>>
>> Am 01.09.2015 08:02, schrieb Edinson E. Padrón Urdaneta:
>>
>>> Hi, everyone.
>>>
>>> I'm trying to understand why the following asserts hold
>>>
>>> // Method
>>> def m(def x) { x }
>>> assert m() == null
>>>
>>> // Closure
>>> def c = { def x -> x }
>>> assert c() == null
>>>
>>> // Constructor
>>> class Klass {
>>> String msg
>>>
>>> Klass(def x) {
>>> this.msg = "$x should be null"
>>> }
>>> }
>>> assert (new Klass()).msg == 'null should be null'
>>>
>>> The arity of the method/closure/constructor is one but I can call it
>>> without any argument at all. What I'm missing?
>>>
>>> Thank you in advance.
>>>
>>
>>
>> --
>> Jochen "blackdrag" Theodorou
>> blog: http://blackdragsview.blogspot.com/
>>
>>
>
|