JDK 16 RFR of JDK-8071961: Add javac lint warning when a default constructor is created

Alex Buckley alex.buckley at oracle.com
Thu Jul 30 07:51:49 UTC 2020


On 7/29/2020 9:32 PM, Joe Darcy wrote:
> Perhaps a bit better as
> 
>      Since it does not declare any explicit constructors, class {0} in 
> exported package {1} of module {2} exposes a default constructor

I get your point about warning for the absence of something, in which 
case the lint warning should be `missing-explicit-ctor` and the message 
should be:

   class {0} in exported package {1} of module {2} is missing an 
explicit constructor; clients rely on the default constructor

However, what if a class explicitly declares a ctor with the same shape 
as the default ctor? JLS 13.1 teaches that a class file doesn't 
distinguish an explicitly declared ctor with the right shape versus the 
implicitly declared ctor. ("the following constructs are declared 
implicitly in source code, but are not marked as mandated because only 
formal parameters can be so marked in a class file: - Default 
constructors of classes ...")

Alex


More information about the compiler-dev mailing list