Hi
I often create enum's with one or more final fields where its a requirement that the field values are unique.
I have created a unit test assertion that will help verify this contract, but I feel it would be nice to have the check at compile time.
So my proposal is to have a @Unique (or similar named) annotation that you can put on any non static final field in an enum and give a compile time error if same value is discovered in more than one enum constant.
Example that should compile fine:
@Getter
@RequiredArgsConstructor
public enum Example1 {
A("a"),
B("b"),
;
@Unique
final String key;
}
Example that should fail due to duplicate key value:
@Getter
@RequiredArgsConstructor
public enum Example2 {
A("a"),
B("b"),
C("b"),
;
@Unique
final String key;
}
Is this outside the scope of lombok?
Best regards Jens