Java enum elements with spaces?

后端 未结 8 706
夕颜
夕颜 2020-12-02 19:07

Im working on java, I have created an enum as follows:

public enum myEnum
{
    india,
    russian,
    england,
    north America
}

Above

8条回答
  •  死守一世寂寞
    2020-12-02 19:24

    The Java naming rule does not allow white spaces as possible characters in a name of variables, classes, enums and enum members (and every other identifier). Therefore this "problem" cannot be resolved. Just use `north_america' as member name!

    An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter.

    The Java letters include uppercase and lowercase ASCII Latin letters A-Z (\u0041-\u005a), and a-z (\u0061-\u007a), and, for historical reasons, the ASCII underscore (_, or \u005f) and dollar sign ($, or \u0024). The $ character should be used only in mechanically generated source code or, rarely, to access preexisting names on legacy systems.

    The "Java digits" include the ASCII digits 0-9 (\u0030-\u0039).

提交回复
热议问题