[Lombok] Constructor can have only non-final or not initialized fields
When using the AllArgsConstructor annotation (directly or via meta-annotation), only fields that are not final or not initialized should be added as arguments. Previously, all fields were being included regardless of modality or initialization, which is not consistent with the behavior of Lombok. ^KT-54054 Fixed
This commit is contained in:
+7
-1
@@ -5,12 +5,18 @@ import lombok.*;
|
||||
@AllArgsConstructor(staticName = "of")
|
||||
public class ConstructorExample {
|
||||
|
||||
// Part of constructor because not final.
|
||||
@Getter @Setter private int age = 10;
|
||||
|
||||
// Part of constructor because not initialized.
|
||||
@Getter(AccessLevel.PROTECTED) private String name;
|
||||
|
||||
// Part of constructor because not initialized.
|
||||
private boolean otherField;
|
||||
|
||||
// Not part of constructor because final and initialized.
|
||||
@Getter private final String result = "OK";
|
||||
|
||||
public ConstructorExample(String arg) {
|
||||
|
||||
}
|
||||
@@ -27,5 +33,5 @@ public class ConstructorExample {
|
||||
fun box(): String {
|
||||
val existing: ConstructorExample = ConstructorExample("existing")
|
||||
val generated: ConstructorExample = ConstructorExample.of(45, "234", false)
|
||||
return "OK"
|
||||
return generated.getResult()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user