我有静态域F类A:BT和继承在Java中
class A {
public static String F = null;
}
类别:
class B extends A {
public static String F = "somestring";
}
并用的方法的类型化的类使用场F:
class C<T extends A> {
public void someMethod() {
String someString = T.F;
// Manipulations with someString
}
}
然后我的代码调用它。
C<B> c = new C<B>();
c.someMethod();
我试图用someString操作时出现空指针异常。所以,T.F是null,但T是B,所以它应该是“somestring”!为什么?