C
Christopher Benson-Manica
Why isn't this legal?
public class TestIt {
private static class Foo<T> {
}
private static class Bar extends Foo<Integer> {
}
private static void Baz( Foo<?> foo ) {
if( foo instanceof Bar ) { // "inconvertible types" error
}
}
}
And since that's not legal, why exactly does it become legal if the
parameter foo is of the raw type Foo? I clearly don't understand
generics completely and it seems perverse that I can't ask a
superclass if it's an instance of a base class just because of the
generic type paramters.
public class TestIt {
private static class Foo<T> {
}
private static class Bar extends Foo<Integer> {
}
private static void Baz( Foo<?> foo ) {
if( foo instanceof Bar ) { // "inconvertible types" error
}
}
}
And since that's not legal, why exactly does it become legal if the
parameter foo is of the raw type Foo? I clearly don't understand
generics completely and it seems perverse that I can't ask a
superclass if it's an instance of a base class just because of the
generic type paramters.