简体   繁体   中英

Use lombok to generate constructor that param takes in additional params

I am refactoring some legacy code, trying to use Lombok to make it a bit cleaner.

Right now the constructor of my class is defined as follows:

public class MyClass {
    private final YourClass yourClass;

    public MyClass(final A a, final B b) {
        yourClass = new YourClass(a, b);
    } 
}

How do I use Lombok to make this happen?

If you have additional parameters of an arbitrary type, there is no way for Lombok (or any other annotation processing mechanism) to determine how you want your constructor to look like and behave.

You will have to define your own constructor or a static factory method. Or use the builder pattern.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM