Skip to content

Instantly share code, notes, and snippets.

@johnzeringue
Last active August 29, 2015 14:08
Show Gist options
  • Save johnzeringue/8e74ce0f299e4d9255a7 to your computer and use it in GitHub Desktop.
Save johnzeringue/8e74ce0f299e4d9255a7 to your computer and use it in GitHub Desktop.
Preinitialization Pattern in Java 8 - Example 1
public class A {
public A(Runnable preinitialization) {
preinitialization.run();
initializeUsingSubclassMethod();
}
}
public class B extends A {
private String variable;
public B(String variable) {
super(() -> {
this.variable = variable;
});
}
public void methodUsedBySuper() {
// do something with variable
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment