I have an enum type...
public static enum Methods {
NOTEQUAL,
ORDERED,
minMatch,
minItem,
minLength,
sameLength,
}
The question is how should I use the coding convention. Should I use camelCase NotEqual
(wich I use in a simple class) or should I do like this: NOT_EQUAL
? Or simply use uppercase characters: NOTEQUAL
, SAMELENGTH
?
Is there some code convention for this?
CA1069: Enums should not have duplicate values (code analysis) - .
Enums in Java (and probably enums in general) should be singular.
equals method uses == operator internally to check if two enum are equal. This means, You can compare Enum using both == and equals method.
The java. lang. Enum. clone() method guarantees that enums are never cloned, which is necessary to preserve their "singleton" status.
I would say that the enum itself, since it's a class, should follow the camel case convention as every class, while the entries of enum, since they are constants, should be upper case with underscore (eg. NOT_EQUAL
).
The version uppercase without underscore is absolutely unreadable, never use it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With