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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值