Java - class name starts with numbers [duplicate]

最后都变了- 提交于 2020-07-30 04:21:21

问题


I have done my HW already but our instructor wants us to submit our HWs as yourID_BFS_DFS.java. And I can't do that, it returns error. I know that numbers are not Java letters and it is illegal (I checked other answers already) but still I want to ask you guys if there is a way (maybe a trick) to do that or he simply wants us to accomplish something illegal? And if I am not wrong, java language is updated recent days, and maybe it is about that, I don't know really.

B.t.w. I can't reach him to ask, he never replies. That's why I am asking here again.


回答1:


The first character needs to be a "Java letter", which includes letters, underscore and dollar sign.

See https://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.8

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 pre-existing names on legacy systems. [...]

Letters and digits may be drawn from the entire Unicode character set, which supports most writing scripts in use in the world today, including the large sets for Chinese, Japanese, and Korean. This allows programmers to use identifiers in their programs that are written in their native languages.




回答2:


Not possible to begin java class with number. I guess he means you should do it in this format "IDxxxxxx_BFS_DFS"

But the best way to understand is ask him for clarifications.



来源:https://stackoverflow.com/questions/50249645/java-class-name-starts-with-numbers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!