What does EnumSet really mean?

后端 未结 10 1518
小蘑菇
小蘑菇 2020-12-04 16:08

I have the following example:

import java.util.EnumSet;
import java.util.Iterator;

public class SizeSet {

    public static void main(String[] args) {
             


        
10条回答
  •  鱼传尺愫
    2020-12-04 16:46

    As for any variable, its type is found in its declaration:

    EnumSet largeSize
    

    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 largeSizes
    

    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.

提交回复
热议问题