Java中的静态最终变量 [英] Static Final Variable in Java
本文介绍了Java中的静态最终变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
私有最终静态属性vs私有最终属性
将变量声明为
static final int x = 5;
或
final int x = 5;
如果我只想将变量设为本地变量并且常量(以后不能更改)?
If I only want to the variable to be local, and constant (cannot be changed later)?
谢谢
推荐答案
刚进行决赛将产生预期效果。
Just having final will have the intended effect.
声明静态使它成为一个类变量,可以通过类名< ClassName> .x来访问。
Declaring static is making it a class variable, this would be accessed through the class name <ClassName>.x.
这篇关于Java中的静态最终变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文