问题
Is there a way that I can define a "PostConstruct" initialization method with lombok?
@RequiredArgsConstructor(staticName = "of")
class MyObj {
private final int x;
private final int y;
private int z;
// not work
@PostConstruct
private void someInitLogic {
z = x + y;
}
public void start() {
// code use "z"
}
}
So that I can init an object like:
MyObj obj = MyObj.of(1, 2);
obj.start();
回答1:
Not yet. There's an open issue named just like your question. Unfortunately, Lombok development is rather slow and there are many feature requests open. Vote for this one (don't add "+1", use the button), if you really care.
来源:https://stackoverflow.com/questions/41156010/is-there-any-postconstruct-feature-of-lombok