I have the following example:
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;
}
In this code I can understand that the Enum creates an Enum type of Sizes.
My question is: is largeSize
an object of EnumSet type? What does it really mean? I really want to understand it better.
As for any variable, its type is found in its declaration:
So yes,
largeSize
(which should be namedlargeSizes
since it's a collection) is of typeEnumSet
. It should also be generified, and thus be declared asWhat it means, is that
largeSizes
is of typeEnumSet
. AnEnumSet
is aSet
which contains enum instance of a specific enum type, in a more efficient way than otherSet
implementations (likeHashSet
,TreeSet
, etc.). To know what anEnumSet
is, read its API.