Last active
August 29, 2015 14:07
-
-
Save Danny02/55f6554e48a65b3a73fa to your computer and use it in GitHub Desktop.
Showcases a compiler bug in the JDK 8_20
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class App { | |
interface B<T>{T get();} | |
interface C<S>{} | |
static void error() { | |
C a = null; | |
/* | |
* No error, but an Error with Java 7(which is correct). | |
* Foo returns a Rawtype which gets mapped to B<Float> | |
*/ | |
B<Float> b = foo(a); | |
/* | |
* compile error: | |
* incompatible types: Object cannot be converted to String | |
* | |
* This wrong error exists, because the compiler thinks that foo returns the Rawtype B | |
*/ | |
String c = foo(a).get(); | |
} | |
/* | |
* if a is a Rawtype the compiler wrongly assumes, that the return type is also a Rawtype. | |
*/ | |
static B<String> foo(C<Integer> a) { | |
return null; | |
} | |
static void working() { | |
C<Integer> a = null; | |
/* | |
* No error, the compiler is correct, that foo returns the parametized type B<String> | |
*/ | |
String c = foo(a).get(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment