Problem with method references
Brian Goetz
brian.goetz at oracle.com
Fri Jan 14 09:44:15 PST 2011
> If we follow method/constructor invocation syntax as closely as possible, existing Java developers would grasp the syntax more quickly.
>
> The only conceptual addition to method/constructor invocation syntax is prefixing instance method / inner class constructor with declaring / enclosing class name:
>
> DeclaringClassName#instanceMethod
>
> EnclosingClassName#new InnerClass;
>
> ... to construct a function that takes an additional 1st argument being an instance of declaring/enclosing class. These two forms have no analogous counterparts as method/constructor invocations so their syntax does not associate to any known concept.
The bytecode would disagree :)
Inner class constructors show up as constructors that take an outer
argument. For a class:
public class Outer {
public class Inner {
}
}
the inner class bytecode looks like
public class Outer$Inner extends java.lang.Object{
final Outer this$0;
public Outer$Inner(Outer);
}
Which means the syntax Inner#new works fine for inner class instances
too -- if you know about the secret first Outer argument.
Given that this is at least a CC^2 (corner case of a corner case) or
even a CC^3, I think we don't want to create new syntax for this.
(Quiz: what percentage of Java developers have used the outer.new
Inner() syntax?)
More information about the lambda-dev
mailing list