Why is const reserved in java




















Keywords in C language. Keywords in Python language. Your email address will not be published. Notify me of follow-up comments by email. Notify me of new posts by email. On October 5, By Karmehavannan 0 Comment Categories: Keyword in Java Tags: Java language , keyword in Java The const keyword in Java programming language The const keyword in java programming language We will learn in this tutorial about The const keyword in Java programming language const is a reserved word in Java language because it is not allowed to be used in Java programmer in coding.

Follow the link to view the analysis, in the outputs of which the problems associated with entering const are noted:. Adding const is too late now. Had this been added from 1. This means that most methods will have to be marked const explicitly. Compatibility is a very important feature of the JDK.

Arguably, the collection classes should be modified to indicate that the elements are const. That would require all existing implementations to be updated in the same way, effectively breaking all existing non-JDK implementations of the collection interfaces.

Similarly, hashCode would have to be const, breaking the current implementation of String. Java has alternative jump operators: break , continue , return , which cover most of the application area. The only argument in favor of goto is that in some cases, using goto allows you to simplify the code.

Apparently, the goto supporters were not able to exert enough influence on the developers to add a new keyword. Some serious people believe that it has no place in programming languages, and write whole books about it. So, while someone is talking about it, the creators of Java are doing it. They sincerely believe that without an unconditional transition, the world will become a little kinder, and on the totality of problems and advantages, you can agree with them.

Can you see reasons for closing the request , does Sun provides any explanations? Sun provided 3 reasons for why they won't act on the request in the request itself. I quote:. In addition to creeping featurism , we see the following problems with this feature:. Adding const is too late now. Had this been added from 1. This means that most methods will have to be marked const explicitly.

Compatibility is a very important feature of the JDK. Arguably, the collection classes should be modified to indicate that the elements are const. That would require all existing implementations to be updated in the same way, effectively breaking all existing non-JDK implementations of the collection interfaces. Similarly, hashCode would have to be const, breaking the current implementation of String.

Somewhat to my surprise, nobody bothered to suggest const. Or if they did, I missed it. So either nobody cares enough for this idea any more, or people with sufficient expertise to formulate a project COIN proposal recognize that there's no chance that it would pass muster.

It is not used because it has no function in Java. I quote from Wikipedia :. Here is another, maybe more reliable source.

Actually, the Wikipedia article you linked has your answer:. An enhancement request ticket for implementing const correctness exists in the Java Community Process, but was closed in on the basis that it was impossible to implement in a backwards-compatible fashion.

How are we doing? Please help us improve Stack Overflow. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 10 years, 2 months ago. Active 9 months ago.



0コメント

  • 1000 / 1000