为什么const关键字没有在Java中使用? [英] Why const keyword is not used in Java?

查看:1062
本文介绍了为什么const关键字没有在Java中使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

为什么Java中没有Constant关键字?

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

你能否看到使用某些传递const或不可变关键字或为什么

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?

你能看到原因关闭请求,Sun是否提供任何解释?

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

推荐答案


你能看到closi的原因吗?在请求时,Sun是否提供任何解释?

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

是。 Sun提供了3个理由说明他们为什么不对请求本身。我引用:

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


目前没有计划将这个功能添加到Java。在
除了爬行特征之外,我们看到以下问题带有此功能的

"There are no current plans to add this feature to Java. In addition to creeping featurism, we see the following problems with this feature:


  • 现在添加const太晚了。这是从1.0添加的,
    情况可能有所不同。

  • Adding const is too late now. Had this been added from 1.0, the situation could have been different.

Const污染:C ++方法要求所有const方法
都用const关键字标记这意味着大多数
方法必须明确地标记为const。这会使
混乱C ++中的所有方法。

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

兼容性这是JDK的一个非常重要的特性。
可以说,集合类应该修改为
表示元素是const。那就是
要求所有现有的实现都在$ b $中更新b以同样的方式,有效地破坏了集合接口的所有现有的非JDK
实现。同样,
hashC ode必须是const,打破String的当前
实现。

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






更新

出于好奇,我花了几分钟时间拖网 Project COIN邮件列表的主题行。令我惊讶的是,没有人打算建议 const 。 (或者,如果他们这样做了,我就错过了。)

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

因此,任何人都不再关心这个想法,或者有足够专业知识来制定项目COIN提案的人认识到它没有机会通过集合。

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.

这篇关于为什么const关键字没有在Java中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆