Denys S.
Denys S.

Reputation: 6525

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)

Upvotes: 1

Views: 253

Answers (3)

Paŭlo Ebermann
Paŭlo Ebermann

Reputation: 74810

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.)

Upvotes: 3

JasCav
JasCav

Reputation: 34652

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

Upvotes: 1

OscarRyz
OscarRyz

Reputation: 199294

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 )

Upvotes: 2

Related Questions