lambda syntax tutorial
Rémi Forax
forax at univ-mlv.fr
Thu Aug 5 07:03:56 PDT 2010
Le 05/08/2010 12:47, Fredrik Ohrstrom a écrit :
>> Uhmm, yes and no.
>> On the one hand, as Fredrik has pointed out, adding overloaded versions
>> of a method to a class can already result in ambiguity errors (best
>> case) or 'stale' resolution (worst case) anywhere else in the codebase.
>>
>> On the other hand, I admit that this syntax is more prone to this kind
>> of problems since the argument list is completely unspecified - but it's
>> just matter of quantity, not quality ;-)
>>
> Well, you could either say that when searching for the most specified
> method target, you take the one with the fewest arguments and supply
> null as the arguments for resolution.
>
> Or you could simply forbid compiling when several overloaded targets exist.
>
>
>> Explicit syntax does not entirely solve the problem, as explicit
>> argument types might still undergo an overload resolution process:
>>
> Exactly, Joe Darcy's blog entry is a good read:
> http://blogs.sun.com/darcy/entry/kinds_of_compatibility
>
> Regarding the question whether adding overloaded methods should be
> considered as source compatible, I quote:
>
> "Adding overloaded methods has the potential to change method
> resolution and thus change the signatures of the method call sites in
> the resulting class file. Whether or not such a change is problematic
> with respect to source compatibility depends on what semantics are
> required and how the different overloaded methods operate on the same
> inputs, which interacts with behavioral equivalence notions."
>
> //Fredrik
>
Ok, I was not crystal clear. Let's take an example,
this code compile.
Following the criterion of Joe, I can add A.m(B) because
its semantics is equivalent to the semantics of A.m(A).
However it will not compile anymore !
class A {
public static A m(A a) { return null; }
//public static A m(B b) { return null; }
}
class B extends A { }
interface Foo<T> {
T m(T t);
}
...
Foo<A> foo = A#m;
It will always compile if the last instruction is:
Foo<A> foo = A#m(A);
Rémi
More information about the lambda-dev
mailing list