Why can an identifier not start with a number?

前端 未结 7 1790
[愿得一人]
[愿得一人] 2020-12-06 16:52

Why in java (I dont know any other programming languages) can an identifier not start with a number and why are the following declarations also not allowed?

         


        
7条回答
  •  一整个雨季
    2020-12-06 17:30

    Every language needs to define what is a valid character for an identifier and what is not. Part of the consideration is going to be ease of parsing, part is going to be to avoid ambiguity (in other words even a perfect parsing algorithm couldn't be sure all the time), part is going to be the preference of the language design (in Java's case similarity with C, C++) and some is just going to be arbitrary.

    The point is it has to be something, so this is what it is.

提交回复
热议问题