EnumSet是什么意思? [英] What does EnumSet really mean?
问题描述
我有以下示例:
import java.util.EnumSet;
import java.util.Iterator;
public class SizeSet {
public static void main(String[] args) {
EnumSet largeSize = EnumSet.of(Size.XL,Size.XXL,Size.XXXL);
for(Iterator it = largeSize.iterator();it.hasNext();){
Size size = (Size)it.next();
System.out.println(size);
}
}
}
enum Size {
S, M, L, XL, XXL, XXXL;
}
在这段代码中,我可以理解,枚举创建一个枚举我的问题是:是 largeSize
EnumSet类型的一个对象?
In this code I can understand that the Enum creates an Enum type of Sizes.
这是什么意思?
推荐答案
对于任何变量,其类型在其声明中找到:
As for any variable, its type is found in its declaration:
EnumSet largeSize
所以是的, largeSize
(它应该命名为 largeSizes
,因为它是一个集合)的类型为$ code > EnumSet 。它也应该被生成,因此被声明为
So yes, largeSize
(which should be named largeSizes
since it's a collection) is of type EnumSet
. It should also be generified, and thus be declared as
EnumSet<Size> largeSizes
这意味着, largeSizes
是 EnumSet
。一个 EnumSet
是一个 Set
,它包含一个特定枚举类型的枚举实例,比其他设置
实现(如 HashSet
, TreeSet
等)。要了解一个 EnumSet
是什么,请阅读其api doc for java 8 。
What it means, is that largeSizes
is of type EnumSet
. An EnumSet
is a Set
which contains enum instance of a specific enum type, in a more efficient way than other Set
implementations (like HashSet
, TreeSet
, etc.). To know what an EnumSet
is, read its api doc for java 8.
这篇关于EnumSet是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!