FULL PRODUCT VERSION :
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Kubuntu 14.04 x64
A DESCRIPTION OF THE PROBLEM :
This works in jdk1.8.0_11 and in Eclipse but not anymore in jdk1.8.0_20:
public class Testbed {
public static void main(String[] args) {
java.util.List<Dog> l = null;
Dog d = l.get(0).copy(); // ok
foo(l.get(0).copy()); // error
}
private static void foo(Dog d) { }
}
class Animal {
public <T> T copy() {
return null;
}
}
class Dog extends Animal {
}
jdk1.8.0_20 message:
Testbed.java:5: error: method foo in class Testbed cannot be applied to given types;
foo(l.get(0).copy()); // error
^
required: Dog
found: Object
reason: argument mismatch; Object cannot be converted to Dog
1 error
REGRESSION. Last worked in version 8u11
ADDITIONAL REGRESSION INFORMATION:
java version "1.8.0_11"
Java(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to compile the given snippet.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
It compiles.
ACTUAL -
Syntax error message.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Testbed.java:5: error: method foo in class Testbed cannot be applied to given types;
foo(l.get(0).copy()); // error
^
required: Dog
found: Object
reason: argument mismatch; Object cannot be converted to Dog
1 error
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Testbed {
public static void main(String[] args) {
java.util.List<Dog> l = null;
Dog d = l.get(0).copy(); // ok
foo(l.get(0).copy()); // error
}
private static void foo(Dog d) { }
}
class Animal {
public <T> T copy() {
return null;
}
}
class Dog extends Animal {
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use jdk1.8.0_11 and be sad.