I'm curious to understand why testInnerClass
fails to compile, citing:
incompatible types: Object cannot be converted to String.
import java.util.List;
class Test<
I extends Test.InnerClass,
S extends Test.StaticInnerClass,
O extends OtherClass> {
void testOtherClass(O other) {
String firstString = other.strings.get(0); //this works
}
void testStaticInnerClass(S staticInner) {
String firstString = staticInner.strings.get(0); //this works
}
void testInnerClass(I inner) {
String firstString = inner.strings.get(0); //this fails:
//"incompatible types: Object cannot be converted to String"
}
static class StaticInnerClass {
List<String> strings;
}
class InnerClass {
List<String> strings;
}
}
class OtherClass {
List<String> strings;
}
testStaticInnerClass
and testOtherClass
work as I would expect but I'm not exactly sure why testInnerClass
fails.