Juan
Juan

Reputation: 275

lombok @Value @NonFinal inheritance

I'm trying to chain several @Value @NonFinal classes without creating any constructors.

Expecting that lombok chooses to generate a constructor that call super with all the arguments that match.

Is there any way of achieving this? It seems to break with an error that doesn't make sense because the father class have such constructor given by the annotation. I tried this with classes in different files, same behaviour.

Example:

public class TestLombok {

@Value
@NonFinal
class A {
    @NonNull Integer a;
}

@Value
@NonFinal
class B extends A {
    String b;
}

}

Error:(12, 5) java: constructor A in class TestLombok.A cannot be applied to given types; required: java.lang.Integer found: no arguments reason: actual and formal argument lists differ in length

Upvotes: 12

Views: 8692

Answers (1)

Roel Spilker
Roel Spilker

Reputation: 34462

Unfortunately, this is not possible.

Finding out what fields or methods a parent class has requires resolution. The moment lombok needs to generate methods, resolution is not possible, since it would change the outcome of the available fields and methods.

Disclosure: I am a lombok developer.

Upvotes: 13

Related Questions