RFR: 8271623: Omit enclosing instance fields from inner classes that don't use it
Alex Buckley
alex.buckley at oracle.com
Tue Aug 3 23:34:10 UTC 2021
On 8/3/2021 12:56 PM, Rafael Winterhalter wrote:
> I do however think that you must retain the constructor to accept the
> outer instance, no matter if it is stored in a field or not. Otherwise,
> a public inner class might change its constructor and introduce a binary
> incompatible change if a field access of the outer class is removed or
> added and this class is recompiled independently. ...
The JLS mandates a constructor parameter for the outer instance --
https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-8.8.1-200
-- and nothing in the patch appears to do away with that parameter.
There's even a comment in Lower.java that "If the variable is never
accessed, we skip creating an outer instance field and saving the
constructor parameter to it." -- implying the parameter still exists.
It would be good for the CSR (JDK-8271717) to clarify that the
T-accepting constructor in class T$I is still present after the change,
and merely invokes a super constructor.
Alex
More information about the compiler-dev
mailing list