What is the difference between constant variables and final variables in java?(java中的常量变量和最终变量有什么区别?)
问题描述
请帮助我理解 Java 中常量变量和 final
变量之间的区别.我有点困惑.
Please help me understand the difference between constant variables and final
variables in Java. I am a bit confused with it.
推荐答案
Constant是概念,是变量的属性.
Constant is the concept, the property of the variable.
final
是声明常量变量的java关键字.
final
is the java keyword to declare a constant variable.
正如其他人指出的那样,从语义/语言的角度来看,表达式 constant variable 是矛盾的,因此,我们可以争论它的正确性.
As other people pointed out, from a semantic/linguistic point of view the expression constant variable is an oxymoron and, as such, we could argue about its correctness.
引用规范,无论如何,我们可以阅读
Quoting the specification, anyway, we can read
原始类型的变量 [...] 是 final 并使用编译时常量表达式(第 15.28 节)进行初始化,称为常量变量.
A variable of primitive type [...], that is final and initialized with a compile-time constant expression (§15.28), is called a constant variable.
因此,我想我们可以接受(并认为是正确的)这个二项式来达到我们的目的.
I suppose, hence, that we can accept (and consider correct) this binomial for our purpose.
这篇关于java中的常量变量和最终变量有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:java中的常量变量和最终变量有什么区别?


- 转换 ldap 日期 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 获取数字的最后一位 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01