Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
546 views
in Technique[技术] by (71.8m points)

java - Is there any "PostConstruct" feature of lombok?

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();
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...