Uncertainty about fix for JDK-5059679

Alex Buckley alex.buckley at oracle.com
Tue Feb 14 02:07:16 UTC 2023


On 2/13/2023 5:06 PM, Dan Smith wrote:
>> On Feb 13, 2023, at 10:28 AM, Archie Cobbs <archie.cobbs at gmail.com> wrote:
>>
>>   * The signature of m1 is not a subsignature (§8.4.2) of the
>>     signature of m2 as a member of the supertype of C that names A.
>>   * The declared signature of m1 or some method m1 overrides (directly
>>     or indirectly) has the same erasure as the declared signature of
>>     m2 or some method m2 overrides (directly or indirectly).
>>
> Note the distinction in these rules between
> 
> "signature of m2 as a member of the supertype of C that names A" (third 
> rule)
> 
> and
> 
> "declared signature of m2" (fourth rule)
> 
> I would interpret the first to mean the signature '(Class<R>)->void', 
> and the second to mean the signature '(T)->void'. Since the erasure of 
> 'T' is 'Object', the fourth rule doesn't apply, and there's no error.

Right, I was headed in this direction too -- the choice of language in 
the different bullets was intended to be significant. I'm happy to agree 
that, after all, no compile-time error is due.


It's something of a surprise that Lower<R> can inherit method(Class<R>) 
_and_ declare method(Class<?>), given that declaring both methods in the 
same class is off-limits. You can even invoke them distinctly.

[ Make both abstract methods concrete; make Upper's method print 1; make 
Lower's method print 2; then add this:

   public static void main(String[] args) {
     Lower<String> a = new Lower<String>();

     Class<String> x = String.class;
     a.method(x);  // prints 1 -- invokevirtual Lower.method(Object)

     Class<?> y = String.class;
     a.method(y);  // prints 2 -- invokevirtual Lower.method(Class)
   }
]

We need to revisit Example 8.4.8.3-4. Erasure Affects Overriding to see 
if it adequately explains the scenario of methods that are different 
enough to not-override, but similar enough to erase (and thus illegal). 
More generally, there is a patchwork of examples -- in 8.4.2, and 
8.4.8.3-4, and 15.12.4.5-1, and now from Archie -- and there is common 
knowledge about erased class file contents, but there is no systematic 
explanation to connect it all up.

Alex


More information about the compiler-dev mailing list