Which class in Java implements the abstract class enumset?

I saw enumset Of() returns an instance of an object of type enumset

Solution

The following are two classes that extend enumset in Java

1. RegularEnumSet
2. JumboEnumSet

You can use the static method of enumset to create instances, such as enumset #noneof, enumset #allof, etc It actually returns an instance of regularenumset or jumboenumset according to the condition Enumset internal call #innset#noneof Please reference the following code from Java to see how enumset #nonof works

public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType) {
    Enum<?>[] universe = getUniverse(elementType);
    if (universe == null)
        throw new ClassCastException(elementType + " not an enum");

    if (universe.length <= 64)
        return new RegularEnumSet<>(elementType,universe);
    else
        return new JumboEnumSet<>(elementType,universe);
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>