I have a problem in creating an enumeration in Java using "-"-separated strings:
public enum CipherList{
RSA-MD5,AES128-SHA,AES256-SHA;
}
I am getting compilation errors.
I have a problem in creating an enumeration in Java using "-"-separated strings:
public enum CipherList{
RSA-MD5,AES128-SHA,AES256-SHA;
}
I am getting compilation errors.
The -
symbol may not be used in an identifier in Java. (How would RSA-MD5
be parsed if RSA
and MD5
happened to be integers?)
I suggest you use
RSA_MD5, AES128_SHA, AES256_SHA;
according to the Java coding conventions for constants related question.
Enum constants have to use valid Java identifiers, and identifiers are not allowed to contain dashes.
You could, for example, replace dashes with underscores:
public enum CipherList{
RSA_MD5, AES128_SHA, AES256_SHA;
}
If you want to use exact strings using enums you can use following approach.
enum CipherList{
CHIP_ONE("RSA-MD5"),CHIP_TWO("AES128-SHA"),CHIP_THREE("AES256-SHA");
private String code;
CipherList(String code) {
code= code;
}
String getcode() {
return code;
}
}