Skip to content

Instantly share code, notes, and snippets.

@loganj
Created July 29, 2009 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loganj/157768 to your computer and use it in GitHub Desktop.
Save loganj/157768 to your computer and use it in GitHub Desktop.
final public class DontDoThis {
static class SuperClass {
SuperClass() {
overridableMethod(); // this is a bad idea. wait, you'll see.
}
protected void overridableMethod() {
}
}
static class SubClass extends SuperClass {
final private Integer myVeryOwnField = 1;
@Override
protected void overridableMethod() {
myVeryOwnField.intValue(); // this is where you will get a NullPointerException
}
}
public static void main(String[] args) {
new SubClass();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment