Created
October 12, 2010 18:50
-
-
Save loganj/622702 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import java.util.Collections; | |
import java.util.Set; | |
class IncompatibleTypes { | |
interface A {} | |
interface B<T> {} | |
static abstract class C<T> { | |
abstract Set<A> getAsForB(B<T> b); | |
} | |
static class B1 implements B<String> {} | |
static class B2 implements B<Integer> {} | |
static class C1 extends C<String> { | |
Set<A> getAsForB(B<String> bstr) { | |
return Collections.emptySet(); | |
} | |
} | |
static class C2 extends C<Integer> { | |
Set<A> getAsForB(B<Integer> bint) { | |
return Collections.emptySet(); | |
} | |
} | |
public static void main(String[] args) { | |
C c = new C1(); | |
B b = new B1(); | |
// $ javac IncompatibleTypes.java | |
// IncompatibleTypes.java:43: incompatible types | |
// found : java.lang.Object | |
// required: IncompatibleTypes.A | |
// for ( A a : c.getAsForB(b) ) { | |
// ^ | |
// Note: IncompatibleTypes.java uses unchecked or unsafe operations. | |
// Note: Recompile with -Xlint:unchecked for details. | |
// 1 error | |
for ( A a : c.getAsForB(b) ) { | |
System.out.println(a); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No compiler error: Since "c" is delcared as C without type params, the return type of getAsForB is just a plain Set...