Last active
August 29, 2015 14:08
-
-
Save johnzeringue/8e74ce0f299e4d9255a7 to your computer and use it in GitHub Desktop.
Preinitialization Pattern in Java 8 - Example 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class A { | |
public A(Runnable preinitialization) { | |
preinitialization.run(); | |
initializeUsingSubclassMethod(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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