gpt4 book ai didi

java - "const"关键字的用途是什么?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:06:16 26 4
gpt4 key购买 nike

为什么const在Java中是保留关键字却没有作用?如果他们决定使用 final 而不是 const 有什么意义?

最佳答案

来自JLS :

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.

从历史的角度,我可以为您提供以下内容quote通过 Josh Bloch从 2003 年开始:

Josh Bloch: We do not have plans to add support for the const keyword to the Java language. It was a mixed blessing in C++; as you know, it's merely advisory, and can cast on or off. Gosling hated it, and did final instead. What you really want is "immutable," but it's a research problem to make this work properly.

关于java - "const"关键字的用途是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10829538/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com