开发者

What's the aim of not used java keyword?

开发者 https://www.devze.com 2023-02-09 06:57 出处:网络
As oracle states, const is a keyword in java. But it is not used开发者_如何学C. So why is it so and what\'s the use of const being a non used keyword in java? (the same goes for goto)From the Java Lan

As oracle states, const is a keyword in java. But it is not used开发者_如何学C. So why is it so and what's the use of const being a non used keyword in java? (the same goes for goto)


From the Java Language Specification:

The keywords const and goto are reserved, even though they are not currently used. This may allow a Java compiler to produce better error messages if these C++ keywords incorrectly appear in programs.

(This wording already was in the first edition, I think.)


To reserved for future usages.

This way, if that keyword is needed in the future, there won't be source code using them, and no code would be break.

For instance, have java had the word in as reserved, the enhanced for loop introducen in Java 5 could have been written as:

for( int i in someInts ) { 
}

But since it wasn't we have:

for( int i : someInts ) { 
}

Instead ( which I think is nicer btw )


Sometimes words are reserved for future purposes. That's most likely the case here.

0

精彩评论

暂无评论...
验证码 换一张
取 消