Files
kotlin-fork/plugins/lombok/testData/box/allArgsConstructorStatic.kt
T
Brian Norman 2ab1e712f8 [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
2024-01-12 14:55:24 +00:00

38 lines
989 B
Kotlin
Vendored

// FILE: ConstructorExample.java
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) {
}
static void javaUsage() {
ConstructorExample existing = new ConstructorExample("existing");
ConstructorExample generated = ConstructorExample.of(45, "234", false);
}
}
// FILE: test.kt
fun box(): String {
val existing: ConstructorExample = ConstructorExample("existing")
val generated: ConstructorExample = ConstructorExample.of(45, "234", false)
return generated.getResult()
}