我有两个类,一个是抽象类,另一个类是扩展抽象类。
public abstract class ClassA {
private Object object;
public ClassA(Object object){
this.object = object;
initialize();
}
protected abstract void initialize();
}
public class ClassB extends ClassA {
private final List<Object> objectList = new ArrayList<>();
public ClassB(Object object){
super(object);
}
@Override
protected void initialize(){
objectList.clear();
//objectList is showing null here when I call .clear() on it!
//How is this possible?
for(Object object : objectList){
NPE!
}
}
}
我不明白上面示例中的ClassB.objectList为什么/如何给我一个NullPointerException。