简体   繁体   English

不同版本的Java中的标识符?

[英]identifiers in java with different versions?

as we "No keyword should be used as an Identifier in java". 正如我们“在Java中不应该将关键字用作标识符”。 But there will be some words like asser or enum or any other which have been added as keyword in version 1.4, 1.5 resp. 但是会有一些像asser或enum之类的单词,或者在1.4和1.5版中作为关键字添加的其他单词。 So if any older version code is used to compile with new javac, what happens if that code contains these words as an identifier? 因此,如果使用任何较旧版本的代码与新的javac进行编译,那么如果该代码包含这些单词作为标识符,会发生什么情况?

When older code uses an identifier that is a keyword in the current version you are trying to compile the code with, you will simply get an error. 当较旧的代码使用标识符作为当前版本的关键字时,您将尝试使用该标识符来编译代码。 The compiler won't be able to tell from the code what version it was written for. 编译器将无法从代码中得知其编写的版本。

You'll get a compile error. 您会得到一个编译错误。 But you can use already compiled classes if you aren't going to make changes in your legacy code. 但是,如果您不打算在旧代码中进行更改,则可以使用已编译的类。

Thanks for your answer, After searching i got to know the answer as, if any keyword is used as an identifier then we have to compile it with its compliant compiler otherwise it gives a compiler error. 谢谢您的回答,在搜索后我就知道了答案,如果将任何关键字用作标识符,则我们必须使用兼容的编译器对其进行编译,否则会出现编译器错误。 So to do that say suppose if my code has a assert as an identifier which works fine with java 1.3. 因此,如果我的代码具有一个断言作为标识符,并且可以在Java 1.3上正常工作,那可以这么说。 So i can compile it as 所以我可以编译为

javac -source 1.3 example.java javac -source 1.3 example.java

which compiles fine. 编译良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM