如果我需要将枚举属性添加到列表中,我该如何声明该列表?让我们假设枚举类是:
public enum Country{ USA, CANADA; }
我想做的事:
List<String> l = new ArrayList<>();
l.add(Country.USA);
需要用什么代替List<String>?
最佳答案
应该是:
List<Country> l = new ArrayList<Country>();
l.add(Country.USA); // That one's for you Code Monkey :)
关于java - 将枚举类型添加到列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6969841/