Why can't Java variable names start with a number?

前端 未结 2 1114
半阙折子戏
半阙折子戏 2020-12-20 14:19

In Java, variable names start with a letter, currency character ($) etc. but not with number, :, or .

Simple question: why is

2条回答
  •  悲哀的现实
    2020-12-20 14:54

    Simply put, it would break facets of the language grammar.

    For example, would 7f be a variable name, or a floating point literal with a value of 7?

    You can conjure others too: if . was allowed then that would clash with the member selection operator: would foo.bar be an identifier in its own right, or would it be the bar field of an object instance foo?

提交回复
热议问题