Method calls vs lambda calls

Alex Blewitt alex.blewitt at gmail.com
Tue Dec 15 05:59:51 PST 2009


This was, of course, a leading question. Now consider:

>>>>>

>>>>> public class Example { #int()       public fortyTwo = #int()  
>>>>> { return 42; }
>>>>>   public int fortyTwo() {
>>>>>     return 6*9;
>>>>>   }
>>>>>   public void run() {
>>>>>     System.out.println(fortyTwo())
>>>>>   }
>>>>> }


Sent from my (new) iPhone

On 15 Dec 2009, at 07:32, Mikael Grev <grev at miginfocom.com> wrote:

> Isn't this comparable to the problem of hiding a field with a local?  
> I mean complexity wise. And I think the times you happen to use the  
> same local name as a field is a lot more common.
>
> If so I think that it will be enough that the IDEs are color coding  
> them.
>
> Disallow overloaded names is unfortunately not an option since  
> adding new methods would then break code more frequently.
>
> Cheers,
> Mikael
>
>
> On 15 dec 2009, at 08.04, Joshua Bloch wrote:
>
>> I think that perhaps some explicit syntax should be required when  
>> invoking a
>> function object.  That would prevent this sort of confusion.
>>
>>        Josh
>>
>> On Mon, Dec 14, 2009 at 12:51 PM, Stefan Schulz <schulz at the- 
>> loom.de> wrote:
>>
>>> You're right, of course.
>>> Same as with instance and local variables.
>>>
>>> Am 14.12.2009 21:37, schrieb Neal Gafter:
>>>> I'd expect the latter to shadow the former (it is in a nested  
>>>> scope, not
>>>> the same scope).
>>>>
>>>> On Mon, Dec 14, 2009 at 12:36 PM, Stefan Schulz <schulz at the-loom.de
>>>> <mailto:schulz at the-loom.de>> wrote:
>>>>
>>>>   Am 14.12.2009 21:07, schrieb Alex Blewitt:
>>>>> public class Example {
>>>>>   public int fortyTwo() {
>>>>>     return 6*9;
>>>>>   }
>>>>>   public void run() {
>>>>>     System.out.println(fortyTwo())
>>>>>     #int() fortyTwo = #int() { return 42; }
>>>>>     System.out.println(fortyTwo())
>>>>>   }
>>>>> }
>>>>>
>>>>> What's the result on the output here?
>>>>
>>>>   I'd suspect a compile error due to defining two "methods"  
>>>> having the
>>>>   same signature in the same scope.
>>>>
>>>>
>>>
>>>
>>
>
>


More information about the lambda-dev mailing list