13

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.

EricSchaefer
  • 25,272
  • 21
  • 67
  • 103
C. K. Young
  • 219,335
  • 46
  • 382
  • 435
  • Do you really want to do that? Do you think it is obvious to even experienced Java programmers what is going on from that line alone? – Tom Hawtin - tackline Jun 20 '13 at 01:11
  • 3
    On the JVM level, inner class constructors are just constructors that additionally take a reference to the outer class. So the mental model is not surprising to me, at least. Granted, I'm not particularly trying to defend its use in a constructor reference expression, just trying to understand the rationale for its removal. – C. K. Young Jun 20 '13 at 01:13

1 Answers1

0

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

user2023577
  • 1,752
  • 1
  • 12
  • 23