本文介绍了在类中声明的枚举类型是否隐式静态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
CoffeeSize {BIG,HUGE,OVERWHELMING}CoffeeSize size;
CoffeeSize size;
}
class CoffeeTest {
public static void main(String [] args)
{
咖啡饮料=新咖啡();
drink.size = Coffee.CoffeeSize.BIG;
}
}
Coffee.CoffeeSize.BIG
:我可以得到 CoffeeSize
只需使用类名称 Coffee
。我认为枚举类型是隐式静态的我是否正确?
解决方案
是的,是的。语言规范甚至这样说。从 JLS第8.9节(枚举):
class Coffee{
enum CoffeeSize{BIG,HUGE,OVERWHELMING}
CoffeeSize size;
}
class CoffeeTest{
public static void main(String[] args)
{
Coffee drink=new Coffee();
drink.size=Coffee.CoffeeSize.BIG;
}
}
Coffee.CoffeeSize.BIG
: i can get CoffeeSize
just using the class name Coffee
. Am I correct when I think the enum type is implicitly static?
解决方案
Yes, it is. The language specification even says so. From the JLS section 8.9 (enums):
这篇关于在类中声明的枚举类型是否隐式静态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!