Skip to content

Instantly share code, notes, and snippets.

@Danny02
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Danny02/55f6554e48a65b3a73fa to your computer and use it in GitHub Desktop.
Save Danny02/55f6554e48a65b3a73fa to your computer and use it in GitHub Desktop.
Showcases a compiler bug in the JDK 8_20
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