63

I am struggling with EnumSet as it surprisingly doesn't have a simple constructor and its methods doesn't like null values.

What I came up with:

EnumSet<MyClass> x = EnumSet.copyOf(Collections.<MyClass>emptySet());

Which somewhat works but doesn't seem right to me.

Stéphane Millien
  • 3,238
  • 22
  • 36
David162795
  • 1,846
  • 3
  • 15
  • 20

2 Answers2

107

Use the method EnumSet.noneOf:

EnumSet<MyClass> x = EnumSet.noneOf(MyClass.class);
Marc Bannout
  • 388
  • 4
  • 15
Jesper
  • 202,709
  • 46
  • 318
  • 350
31

Use EnumSet.noneOf(Class) to create an empty EnumSet.

Fabian Barney
  • 14,219
  • 5
  • 40
  • 60