This question already has answers here:
In Java, are enum types inside a class static?

(2个答案)


4年前关闭。



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:我可以使用类名CoffeeSize来获取Coffee。我认为枚举类型隐式静态时正确吗?

最佳答案

是的。语言规范甚至是这样说的。从JLS section 8.9 (enums):

07-28 00:24