Last active
August 29, 2015 14:08
-
-
Save johnzeringue/dab6eda0b0acbe2c4018 to your computer and use it in GitHub Desktop.
Preinitialization Pattern in Java 8 - Example 2
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
import java.util.function.Consumer; | |
public class A<T extends A> { | |
public A(Consumer<T> preinitialization) { | |
preinitialization.accept((T) this); | |
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
import java.util.function.Consumer; | |
public class B extends A<B> { | |
private String variable; | |
public B(String variable) { | |
super(self -> { | |
self.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