JDK-8015879 : Inference regression from Java 7
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2013-06-04
  • Updated: 2013-06-04
  • Resolved: 2013-06-04
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version  " 1.8.0-ea " 
Java(TM) SE Runtime Environment (build 1.8.0-ea-b92)
Java HotSpot(TM) Client VM (build 25.0-b34, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
The new inference rules cause existing code to no longer compile.

REGRESSION.  Last worked in version 7u40

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to compile the given code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code should compile, as it does under Java 7.
ACTUAL -
The code does not compile.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java: method doNumber in class java8.InferenceTest cannot be applied to given types;
  required: java.lang.Class<N>
  found: java.lang.Class<capture#1 of ? extends java.lang.Number>
  reason: cannot infer type-variable(s) N,U
    (argument mismatch; java.lang.Class<capture#2 of ? extends java.lang.Number> cannot be converted to java.lang.Class<capture#3 of ? extends java.lang.Number>)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package java8;

public class InferenceTest
{
private void test () {
Class<?> c1 = Integer.class;
doNumber (c1.asSubclass (Number.class));
final Class<? extends Number> c2 = c1.asSubclass (Number.class);
doNumber (c2);
}

private <N extends Number> void doNumber (Class<N> type) {}
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
The workaround is to introduce a local variable, as in line 8