本文介绍了是否有任何"PostConstruct"龙目岛的特点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以用lombok定义"PostConstruct"初始化方法?

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.

这篇关于是否有任何"PostConstruct"龙目岛的特点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-12 06:08