What are the rules for characters that can be used in Java variable names?
Rules are specified in the JLS for identifiers, section 3.8 . You are interested in Character.isJavaIdentifierPart :
A character can be part of a Java identifier if one of the following conditions is true:
- this letter
- it is a currency symbol (e.g. $$)
- it is a connecting punctuation character (for example, "_")
- this is a figure
- it is a numeric letter (e.g. Roman numeral character)
- it is a combining sign
- it is a sign without a space
- isIdentifierIgnorable (codePoint) returns true for the character
Of course, it is assumed that you compile your code with the appropriate encoding.
The character you are apparently trying to use is U + 1D11E , which is none of the above. This is a musical treble clef, which is located in the "Symbols, Others" category.
source share