简体   繁体   中英

What's the aim of not used java keyword?

As oracle states , const is a keyword in java. But it is not used . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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