java.lang.Enum.getSharedConstants()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(203)

本文整理了Java中java.lang.Enum.getSharedConstants()方法的一些代码示例,展示了Enum.getSharedConstants()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Enum.getSharedConstants()方法的具体详情如下:
包路径:java.lang.Enum
类名称:Enum
方法名:getSharedConstants

Enum.getSharedConstants介绍

[英]Returns a shared, mutable array containing the constants of this enum. It is an error to modify the returned array.
[中]返回包含此枚举常量的共享可变数组。修改返回的数组是错误的。

代码示例

代码示例来源:origin: robovm/robovm

private void initialization(Class<K> type) {
  keyType = type;
  keys = Enum.getSharedConstants(keyType);
  enumSize = keys.length;
  values = new Object[enumSize];
  hasMapping = new boolean[enumSize];
}

代码示例来源:origin: robovm/robovm

/**
 * Returns the {@code enum} constants associated with this {@code Class}.
 * Returns {@code null} if this {@code Class} does not represent an {@code
 * enum} type.
 */
@SuppressWarnings("unchecked") // we only cast after confirming that this class is an enum
public T[] getEnumConstants() {
  if (!isEnum()) {
    return null;
  }
  return (T[]) Enum.getSharedConstants((Class) this).clone();
}

代码示例来源:origin: robovm/robovm

@MarshalsValue
public static <T extends Enum<T>> T toObject(Class<T> cls, int ordinal, long flags) {
  T[] values = Enum.getSharedConstants(cls);
  if (values.length == 0) {
    throw new AssertionError("Enum class has no values!");
  }
  if (ordinal < 0 || ordinal >= values.length) {
    Class<?> enumType = values[0].getClass();
    throw new IllegalArgumentException("No constant with ordinal " 
        + ordinal + " in " + enumType.getName());
  }
  return values[ordinal];
}

代码示例来源:origin: robovm/robovm

throw new NullPointerException("name == null");
T[] values = getSharedConstants(enumType);
if (values == null) {
  throw new IllegalArgumentException(enumType + " is not an enum type");

代码示例来源:origin: robovm/robovm

@MarshalsValue
public static <T extends Enum<T> & ValuedEnum> ValuedEnum toObject(Class<T> cls, long value, long flags) {
  T[] values = Enum.getSharedConstants(cls);
  int length = values.length;
  if (length == 0) {
    throw new AssertionError("Enum class has no values!");
  }
  for (int i = 0; i < length; i++) {
    Enum<?> e = values[i];
    ValuedEnum v = (ValuedEnum) e;
    if (v.value() == value) {
      return v;
    }
  }
  Class<?> enumType = values[0].getClass();
  throw new IllegalArgumentException("No constant with value " 
      + value + " (0x" + Long.toHexString(value) + ") found in " 
      + enumType.getName());
}

代码示例来源:origin: robovm/robovm

/**
 * Creates an empty enum set. The permitted elements are of type
 * Class&lt;E&gt;.
 *
 * @param elementType
 *            the class object for the elements contained.
 * @return an empty enum set, with permitted elements of type {@code
 *         elementType}.
 * @throws ClassCastException
 *             if the specified element type is not and enum type.
 */
public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType) {
  if (!elementType.isEnum()) {
    throw new ClassCastException(elementType.getClass().getName() + " is not an Enum");
  }
  E[] enums = Enum.getSharedConstants(elementType);
  if (enums.length <= 64) {
    return new MiniEnumSet<E>(elementType, enums);
  }
  return new HugeEnumSet<E>(elementType, enums);
}

代码示例来源:origin: MobiVM/robovm

private void initialization(Class<K> type) {
  keyType = type;
  keys = Enum.getSharedConstants(keyType);
  enumSize = keys.length;
  values = new Object[enumSize];
  hasMapping = new boolean[enumSize];
}

代码示例来源:origin: com.gluonhq/robovm-rt

private void initialization(Class<K> type) {
  keyType = type;
  keys = Enum.getSharedConstants(keyType);
  enumSize = keys.length;
  values = new Object[enumSize];
  hasMapping = new boolean[enumSize];
}

代码示例来源:origin: ibinti/bugvm

private void initialization(Class<K> type) {
  keyType = type;
  keys = Enum.getSharedConstants(keyType);
  enumSize = keys.length;
  values = new Object[enumSize];
  hasMapping = new boolean[enumSize];
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

private void initialization(Class<K> type) {
  keyType = type;
  keys = Enum.getSharedConstants(keyType);
  enumSize = keys.length;
  values = new Object[enumSize];
  hasMapping = new boolean[enumSize];
}

代码示例来源:origin: com.bugvm/bugvm-rt

private void initialization(Class<K> type) {
  keyType = type;
  keys = Enum.getSharedConstants(keyType);
  enumSize = keys.length;
  values = new Object[enumSize];
  hasMapping = new boolean[enumSize];
}

代码示例来源:origin: MobiVM/robovm

/**
 * Returns the {@code enum} constants associated with this {@code Class}.
 * Returns {@code null} if this {@code Class} does not represent an {@code
 * enum} type.
 */
@SuppressWarnings("unchecked") // we only cast after confirming that this class is an enum
public T[] getEnumConstants() {
  if (!isEnum()) {
    return null;
  }
  return (T[]) Enum.getSharedConstants((Class) this).clone();
}

代码示例来源:origin: ibinti/bugvm

/**
 * Returns the {@code enum} constants associated with this {@code Class}.
 * Returns {@code null} if this {@code Class} does not represent an {@code
 * enum} type.
 */
@SuppressWarnings("unchecked") // we only cast after confirming that this class is an enum
public T[] getEnumConstants() {
  if (!isEnum()) {
    return null;
  }
  return (T[]) Enum.getSharedConstants((Class) this).clone();
}

代码示例来源:origin: MobiVM/robovm

@MarshalsValue
public static <T extends Enum<T>> T toObject(Class<T> cls, int ordinal, long flags) {
  T[] values = Enum.getSharedConstants(cls);
  if (values.length == 0) {
    throw new AssertionError("Enum class has no values!");
  }
  if (ordinal < 0 || ordinal >= values.length) {
    Class<?> enumType = values[0].getClass();
    throw new IllegalArgumentException("No constant with ordinal " 
        + ordinal + " in " + enumType.getName());
  }
  return values[ordinal];
}

代码示例来源:origin: ibinti/bugvm

@MarshalsValue
public static <T extends Enum<T>> T toObject(Class<T> cls, int ordinal, long flags) {
  T[] values = Enum.getSharedConstants(cls);
  if (values.length == 0) {
    throw new AssertionError("Enum class has no values!");
  }
  if (ordinal < 0 || ordinal >= values.length) {
    Class<?> enumType = values[0].getClass();
    throw new IllegalArgumentException("No constant with ordinal " 
        + ordinal + " in " + enumType.getName());
  }
  return values[ordinal];
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

/**
 * Returns the {@code enum} constants associated with this {@code Class}.
 * Returns {@code null} if this {@code Class} does not represent an {@code
 * enum} type.
 */
@SuppressWarnings("unchecked") // we only cast after confirming that this class is an enum
public T[] getEnumConstants() {
  if (!isEnum()) {
    return null;
  }
  return (T[]) Enum.getSharedConstants((Class) this).clone();
}

代码示例来源:origin: com.bugvm/bugvm-rt

/**
 * Returns the {@code enum} constants associated with this {@code Class}.
 * Returns {@code null} if this {@code Class} does not represent an {@code
 * enum} type.
 */
@SuppressWarnings("unchecked") // we only cast after confirming that this class is an enum
public T[] getEnumConstants() {
  if (!isEnum()) {
    return null;
  }
  return (T[]) Enum.getSharedConstants((Class) this).clone();
}

代码示例来源:origin: com.gluonhq/robovm-rt

/**
 * Returns the {@code enum} constants associated with this {@code Class}.
 * Returns {@code null} if this {@code Class} does not represent an {@code
 * enum} type.
 */
@SuppressWarnings("unchecked") // we only cast after confirming that this class is an enum
public T[] getEnumConstants() {
  if (!isEnum()) {
    return null;
  }
  return (T[]) Enum.getSharedConstants((Class) this).clone();
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

@MarshalsValue
public static <T extends Enum<T>> T toObject(Class<T> cls, int ordinal, long flags) {
  T[] values = Enum.getSharedConstants(cls);
  if (values.length == 0) {
    throw new AssertionError("Enum class has no values!");
  }
  if (ordinal < 0 || ordinal >= values.length) {
    Class<?> enumType = values[0].getClass();
    throw new IllegalArgumentException("No constant with ordinal " 
        + ordinal + " in " + enumType.getName());
  }
  return values[ordinal];
}

代码示例来源:origin: com.bugvm/bugvm-rt

@MarshalsValue
public static <T extends Enum<T>> T toObject(Class<T> cls, int ordinal, long flags) {
  T[] values = Enum.getSharedConstants(cls);
  if (values.length == 0) {
    throw new AssertionError("Enum class has no values!");
  }
  if (ordinal < 0 || ordinal >= values.length) {
    Class<?> enumType = values[0].getClass();
    throw new IllegalArgumentException("No constant with ordinal " 
        + ordinal + " in " + enumType.getName());
  }
  return values[ordinal];
}

相关文章