1
有沒有一種方法可以用lombok定義一個「PostConstruct」初始化方法?龍目島有沒有「PostConstruct」功能?
@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"
}
}
所以,我可以像初始化對象:
MyObj obj = MyObj.of(1, 2);
obj.start();