Last active
August 29, 2015 14:17
-
-
Save evant/5492a2fe34ac241f5a21 to your computer and use it in GitHub Desktop.
Why doesn't this compile?
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
public class Wtf { | |
public static abstract class Foo<V> { // Removing this type parameter allows it to compile | |
public <T> T bad(Class<T> fooClass) { | |
return null; | |
} | |
} | |
public static class Bar { | |
} | |
public static class Baz extends Foo { | |
public <T> T good(Class<T> fooClass) { | |
return null; | |
} | |
public void go() { | |
Bar badBar = bad(Bar.class); // This won't compile | |
Bar goodBar = good(Bar.class); // But this will | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
javac 1.7.0_75 to compile java sources
Errors occurred while compiling module 'Wtf'
Compilation completed with 1 error and 0 warnings in 1 sec
src/com/example/Wtf.java
Error:(22, 29) java: incompatible types
required: com.example.Wtf.Bar
found: java.lang.Object
src/com/example/Wtf.java uses unchecked or unsafe operations.
Recompile with -Xlint:unchecked for details.