简体   繁体   English

lombok @Value @NonFinal继承

[英]lombok @Value @NonFinal inheritance

I'm trying to chain several @Value @NonFinal classes without creating any constructors. 我试图链接几个@Value @NonFinal类而不创建任何构造函数。

Expecting that lombok chooses to generate a constructor that call super with all the arguments that match. 期望lombok选择生成一个构造函数,该构造函数使用匹配的所有参数调用super。

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; 错误:(12,5)java:类TestLombok.A中的构造函数A不能应用于给定的类型; required: java.lang.Integer found: no arguments reason: actual and formal argument lists differ in length required:java.lang.Integer found:无参数原因:实际和形式参数列表的长度不同

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. 当lombok需要生成方法时,解决方案是不可能的,因为它会改变可用字段和方法的结果。

Disclosure: I am a lombok developer. 披露:我是一名lombok开发者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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