简体   繁体   中英

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

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.

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