Skip to content

Instantly share code, notes, and snippets.

@spacekookie
Last active June 9, 2019 09:13
Show Gist options
  • Save spacekookie/bfe495048646fb76960ca02b00d55569 to your computer and use it in GitHub Desktop.
Save spacekookie/bfe495048646fb76960ca02b00d55569 to your computer and use it in GitHub Desktop.
Easy lambda init pattern
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