1

This is my simple class

@Value
public class Task {
    private static int numberOfTasks = 0;
    private int id = ++numberOfTasks;
    private String name;
    private Timestamp startTime;
    private Timestamp endTime;
}

Reading the Documentation of @Value, It says:

In practice, @Value is shorthand for: final @ToString @EqualsAndHashCode @AllArgsConstructor @FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE) @Getter,

So that means there is a AllArguConstructor. However, If I try to make the field as final, I get a compiler error that the filed is not initialised.

(though also Lombok claims to make the field as final in the case of @Value)

Could anyone help here?

This is what I mean:

enter image description here

Marco Dinatsoli
  • 10,322
  • 37
  • 139
  • 253

0 Answers0