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

Joe Darcy joe.darcy at oracle.com
Thu Jul 30 17:15:10 UTC 2020

On 7/30/2020 12:51 AM, Alex Buckley wrote:
> 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 ...")
Operationally, the warning is only issued if the compiler generates the 
default constructor when compiling the source file.


More information about the compiler-dev mailing list