OPK
OPK

Reputation: 4180

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?

Upvotes: 1

Views: 214

Answers (1)

Michael
Michael

Reputation: 1184

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.

Upvotes: 2

Related Questions