What's the aim of not used java keyword?
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
andgoto
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.
精彩评论