EnumSet

Hi,

I just had a look at the new EnumSet in v1.5:

http://java.sun.com/j2se/1.5.0/docs/api/java/util/EnumSet.html

Why do they proide these "of" mehtods instead of:

static <Eextends Enum><E>> EnumSet<E> of(E... e)

or

static <Eextends Enum><E>> EnumSet<E> of(E[] e)

?

-Puce

[503 byte] By [Pucea] at [2007-9-30 0:31:09]
# 1
EnumSets are meant to be truly fast, and if you want to create a set with lots of elements (more than 5), you can use the plain vanilla Collections.addAll().
edsonwa at 2007-7-16 5:02:09 > top of Java-index,Archived Forums,Java Programming...
# 2

The creation time of course depends on the nuber of elements initially added. But EnumSet is not only usefull to create fastly a Set, but to have a fast Set afterwards (the operations on the Set are likely fast). The EnumSet in fact has methods to add more than five elements (like "allOf", "range", "add" etc.). So this does not explain why the "of" methods are written like this.

-Puce

Pucea at 2007-7-16 5:02:09 > top of Java-index,Archived Forums,Java Programming...