Last active
June 9, 2019 09:13
-
-
Save spacekookie/bfe495048646fb76960ca02b00d55569 to your computer and use it in GitHub Desktop.
Easy lambda init pattern
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 interface MyCreator { | |
void create(MyClass mc); | |
} | |
// ... | |
class MyClass { | |
// ... | |
public MyClass create(MyCreator creator) { | |
MyClass mc = new MyClass(); | |
creator.create(mc); | |
return mc; | |
} | |
} | |
// ... | |
void foobar() { | |
MyClass mc = MyClass.create((mc) -> { | |
mc.setFoo(true); | |
mc.setBar("Something"); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment