In the current JSR 335 draft, it's mentioned in the change log entry for 0.6.0 that it "eliminated support for unbound inner class constructor references".
To illustrate, suppose you have an outer class named A
and an inner class named B
, and you want a function that takes an A
and creates a new B
instance:
Function<A, A.B> foo = a -> a.new B();
Prior to 0.6.0, you can also use the constructor reference syntax to do the same thing (it's even documented in State of the Lambda):
Function<A, A.B> foo = A.B::new;
As mentioned above, that syntax is no longer supported in 0.6.0. I'm really curious to know why.
I've looked through the archives for the lambda-spec-experts
and lambda-dev
mailing lists, and cannot find any information about it.
It's evident that the 'new' is a keyword, not a method, and that all involvment of 'new' as a method are special cases in the compiler. I can easily imagine they wanted to clean up the compiler of least likely usages which have trivial workarounds.
Speculation: there maybe also some collisions/ambiguities to resolve with upcoming JLS we don't know about yet, and this is a transition change to minimize regressions. 5-6 years after your question, do you suffer at all from this change? LOL
来源:https://stackoverflow.com/questions/17203781/java-lambdas-jsr-335-why-eliminate-support-for-unbound-inner-class-construct