2

I have noticed that there is the const keyword in Java. It reminded me of things like static and final variables there.

But why was it created without anyone actually using it?

Armen Michaeli
  • 8,625
  • 8
  • 58
  • 95
  • 3
    @ItamarGreen People are using it how? It's a keyword, but it doesn't appear in the grammar. What are you talking about? – user207421 May 07 '17 at 09:59
  • @JoeC *et al.* This is not a duplicate of that question. This one is about why the keyword exists, not why the feature doesn't exist. – user207421 May 07 '17 at 10:13
  • This was a very, very early decision in the design of Java. I suspect the designers wanted to leave their options open, in case they wished to add a `const` facility to Java in the future. – Dawood ibn Kareem May 08 '17 at 05:18
  • @DawoodibnKareem The reason is clearly stated in the [JLS](http://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.9), and your suspicion does not form part of it. – user207421 May 08 '17 at 10:21

1 Answers1

10

From the JLS #3.9:

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.

user207421
  • 305,947
  • 44
  • 307
  • 483