I have a problem here. I created SpecialCharacterField.java - an enum class that will list some special characters.
SpecialCharacterField.java
package bp.enumfield;
public enum SpecialCharacterField {
+, #;
}
In my eclipse on the line : public enum SpecialCharacterField{
there is an error it says: Syntax error, insert "EnumBody" to complete EnumDeclaration
Please help. Thanks in advance.
do something like this,
public enum SpecialCharacterField{
PLUS("+"),
HASH("#");
private String value;
private SpecialCharacterField(String value)
{
this.value = value;
}
public String toString()
{
return this.value; //This will return , # or +
}
}
Those characters cannot be parts of identifiers in the Java language. Note that the JVM itself imposes no such restrictions (only ./; and [ are prevented), so you could use names like that if you wrote bytecode directly. However this is usually not a desirable approach.
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