java关键字const,为什么const关键字没有在Java中使用?

编程入门 行业动态 更新时间:2024-10-24 16:24:33

java<a href=https://www.elefans.com/category/jswz/34/1769821.html style=关键字const,为什么const关键字没有在Java中使用?"/>

java关键字const,为什么const关键字没有在Java中使用?

Why const keyword is not used in Java?

Can you see any disadvantages of using some transitive const or immutable keyword in Java syntax or why common cumbersome approach was chosen?

Can you see reasons for closing the request, does Sun provides any explanations?

解决方案

Can you see reasons for closing the request, does Sun provides any explanations?

Yes. Sun provided 3 reasons for why they won't act on the request in the request itself. I quote:

"There are no current plans to add this feature to Java. 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.0,

the situation could have been different.

Const pollution: the C++ approach requires all const methods

to be marked with a const keyword. This means that most

methods will have to be marked const explicitly. This tend

to clutter all methods in C++.

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

UPDATE

Out of curiousity, I spent a few minutes trawling through the subject lines of the Project COIN mailing list. 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.

更多推荐

java关键字const,为什么const关键字没有在Java中使用?

本文发布于:2024-02-11 20:46:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1683384.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:关键字   java   Java   const

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!