What type of token exactly is “var” in Java 10?

前端 未结 2 796
春和景丽
春和景丽 2020-12-09 16:27

In the last issue of Heinz Kabutz\'s newsletter, #255 Java 10: Inferred Local Variables, it is shown that var is not a reserved word in Java 10, because you can

2条回答
  •  孤街浪徒
    2020-12-09 17:27

    According to JEP-286: Local-Variable Type Inference, var is

    not a keyword; instead it is a reserved type name.

    (Earlier versions of the JEP left room for implementing either as a reserved type name or as a context-sensitive keyword; the former path was ultimately chosen.)

    Because it's not a "reserved keyword", it is possible to still use it in variable names (and package names), but not in class or interface names.

    I would think the biggest reason for not making var a reserved keyword is backwards compatibility with old source code.

提交回复
热议问题