Can anyone comment with their opinion on the best way to resolve the following issue? I've tried init blocks and initializing the field in the constructor, but neither get called before the overridden method tries to clear it.
class TestRunner {
public static void main(String[] args) {
ftw ftw = new ftw();
ftw.dontPanic();
}
}
class wtf {
wtf(){
this.dontPanic();
}
void dontPanic() {
System.out.println("super don't panic");
}
}
class ftw extends wtf {
final HashSet variableOfDoom = new HashSet();
ftw(){
super();
}
void dontPanic() {
super.dontPanic();
System.out.println("sub don't panic");
variableOfDoom.clear(); //This line prints a null pointer exception, because the field hasn't been intialized yet.
}
}