Latest draft of Defender Methods

Reinier Zwitserloot reinier at zwitserloot.com
Mon Aug 16 15:00:27 PDT 2010


Is there a changelog of some sort? PDF documents are kind of hard to diff.

A second somewhat obscure note: The syntax for the default method does not
include a parameter list. Instead, presumably, if the class+method name is
not unique (i.e. its been overloaded), then the right method is deduced from
the parameter list of the extension method.

However, para 8.2 defines the relation between an extension method's
signature and the implementation of it in terms of what the extension
signature should look like given the implementation. That's catch-22, then -
you can't check if the signature of the default method is legit until you
know which exact implementation method is being pointed at via 'default X',
but you can't know which method is pointed at until you've sorted out the
signature of the extension method.

That's just a spec technicality, but there's also a legitimate technical
issue here: What if the method is overloaded, and more than one overloaded
method would 'fit', i.e. I have:

extension int foo(Integer n) default X.bar;

as well as, in public class X:

public static int foo(Number n) { return 0; }
public static int foo(Integer n) { return 1; }

it's fairly obvious that the intent is to 'find' the 1-returning variant.
However, (A) is this clear in the spec, and (B) should the notion be
supported that one might want to explicitly pick the Number variant? Writing
your own static method that invokes the right 'foo' is not that hard to do,
but on the other hand, the fix is simple: Allow an optional param type list.
Thus, I could write:

extension int foo(Integer n) default X.bar(Number);

And, if this syntax is allowed, should a param-type-less default reference
simply fail at compile time if the reference is ambiguous, instead of
attempting the usual complicated method resolution algorithm?

Some sort of 'ambiguous' error must always be an option. For example, if the
interface's extension method signature reads (Integer, Integer), and there
are 2 valid methods, one with signature (Integer, Number) and the other with
(Number, Integer).


 --Reinier Zwitserloot



On Mon, Aug 16, 2010 at 9:01 PM, Brian Goetz <brian.goetz at oracle.com> wrote:

> I've posted a new draft of Defender Methods at:
>
>
> http://cr.openjdk.java.net/~briangoetz/lambda/Defender%20Methods%20v3.pdf
>
>
>


More information about the lambda-dev mailing list