为何倾向于使用Enum类,而不是static 变量

为什么倾向于使用Enum类,而不是static 变量可能你有这样的疑惑:public class PartyNeeds {public static f

为什么倾向于使用Enum类,而不是static 变量
可能你有这样的疑惑:

public class PartyNeeds {       public static final int PLATES = 1;       public static final int CUPS = 2; } public enum EPartyNeeds {       PLATES,CUPS;}


两个写法的用途都是一样的,但是为什么倾向于后者呢?
假设你的调用方法是这样设计的: void method(PartyNeeds pn){}  ||  void method(EPartyNeeds epn){}
很显然,2个方式你都可以传入1和2进去,但是,如果有人捣乱想传入3或者其他数字呢?除非你在枚举中添加了那个数值,否则你无法传。