Is there a workaround to be able to use colons as the key in enums?
public enum foo {
_DEFAULT_GET("com.foo.my.package"); // works fine
_PREFIX_GET("com.foo.my.other.package");
_PRE:CODE_GET("com.foo.yet.another.package"); // <-- how do I escape this colon?
}
EDIT: before I get downvoted into oblivion, I’d like to add that there was a naming convention change that was handed down. It has caused quite a fun debate in the team! 🙂
No,
:is not a legal character in a Java identifer.The legal characters are, a-z A-Z, 0-9, (
the {unicode letters}), _ and $You’re trying to do the same as
Also your program shouldn’t depend on the names you give to the fields. Unless you do reflection; and you shouldn’t need that, either…
Note that you shouldnt use the $ in your identifiers since its used by code-generators mostly, such as javac when it compiles a class containing an inner class $ is used as separator.
As @Kevin.K mentioned, a-zA-Z is actually unicode letter code.