本文整理了Java中java.lang.Class.isEnum()
方法的一些代码示例,展示了Class.isEnum()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Class.isEnum()
方法的具体详情如下:
包路径:java.lang.Class
类名称:Class
方法名:isEnum
[英]Tests whether the class represented by this Class is an enum.
[中]测试此类表示的类是否为枚举。
代码示例来源:origin: apache/incubator-dubbo
@Override
public boolean accept(Type type, Class<?> clazz) {
if (clazz == null) {
return false;
}
return clazz.isEnum();
}
代码示例来源:origin: apache/incubator-dubbo
@Override
public boolean accept(Type type, Class<?> clazz) {
if (clazz == null) {
return false;
}
return clazz.isEnum();
}
代码示例来源:origin: libgdx/libgdx
/** Determines if the supplied Class object represents an enum type. */
static public boolean isEnum (Class c) {
return c.isEnum();
}
代码示例来源:origin: libgdx/libgdx
/** Determines if the supplied Class object represents an enum type. */
static public boolean isEnum (Class c) {
return c.isEnum();
}
代码示例来源:origin: google/guava
/** Creates an empty {@code EnumMultiset}. */
private EnumMultiset(Class<E> type) {
this.type = type;
checkArgument(type.isEnum());
this.enumConstants = type.getEnumConstants();
this.counts = new int[enumConstants.length];
}
代码示例来源:origin: apache/incubator-dubbo
/**
* Determine if the object needs wrap
*
* @param clazz object type
* @return need wrap
*/
public static boolean needWrapper(Class<?> clazz) {
return WrapperUtils.WRAPPER_SET.contains(clazz) || clazz.isArray() || clazz.isEnum();
}
代码示例来源:origin: apache/incubator-dubbo
/**
* Determine if the object needs wrap
*
* @param clazz object type
* @return need wrap
*/
public static boolean needWrapper(Class<?> clazz) {
return WrapperUtils.WRAPPER_SET.contains(clazz) || clazz.isArray() || clazz.isEnum();
}
代码示例来源:origin: apache/incubator-dubbo
public EnumSerializer(Class cl) {
// hessian/32b[12], hessian/3ab[23]
if (!cl.isEnum() && cl.getSuperclass().isEnum())
cl = cl.getSuperclass();
try {
_name = cl.getMethod("name", new Class[0]);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: spring-projects/spring-framework
public static Class<?> getEnumType(Class<?> targetType) {
Class<?> enumType = targetType;
while (enumType != null && !enumType.isEnum()) {
enumType = enumType.getSuperclass();
}
Assert.notNull(enumType, () -> "The target type " + targetType.getName() + " does not refer to an enum");
return enumType;
}
代码示例来源:origin: apache/incubator-dubbo
public EnumDeserializer(Class cl) {
// hessian/33b[34], hessian/3bb[78]
if (cl.isEnum())
_enumType = cl;
else if (cl.getSuperclass().isEnum())
_enumType = cl.getSuperclass();
else
throw new RuntimeException("Class " + cl.getName() + " is not an enum");
try {
_valueOf = _enumType.getMethod("valueOf",
new Class[]{Class.class, String.class});
} catch (Exception e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public Object readValue(Class<?> c, Object jv) throws IOException {
if (jv == null) {
return null;
}
Decoder decoder = GlobalDecoderMap.get(c);
if (decoder != null) {
return decoder.decode(jv);
}
if (c.isEnum()) {
return Enum.valueOf((Class<Enum>) c, String.valueOf(jv));
}
return jv;
}
代码示例来源:origin: apache/incubator-dubbo
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public Object readValue(Class<?> c, Object jv) throws IOException {
if (jv == null) {
return null;
}
Decoder decoder = GlobalDecoderMap.get(c);
if (decoder != null) {
return decoder.decode(jv);
}
if (c.isEnum()) {
return Enum.valueOf((Class<Enum>) c, String.valueOf(jv));
}
return jv;
}
代码示例来源:origin: org.mockito/mockito-core
private void checkNotEnum(Field field) {
if(field.getType().isEnum()) {
throw new MockitoException("the type '" + field.getType().getSimpleName() + "' is an enum.");
}
}
代码示例来源:origin: prestodb/presto
/** Creates an empty {@code EnumMultiset}. */
private EnumMultiset(Class<E> type) {
this.type = type;
checkArgument(type.isEnum());
this.enumConstants = type.getEnumConstants();
this.counts = new int[enumConstants.length];
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void visit(String attributeName, Object attributeValue) {
Object newValue = attributeValue;
Object existingValue = this.attributes.get(this.attributeName);
if (existingValue != null) {
newValue = ObjectUtils.addObjectToArray((Object[]) existingValue, newValue);
}
else {
Class<?> arrayClass = newValue.getClass();
if (Enum.class.isAssignableFrom(arrayClass)) {
while (arrayClass.getSuperclass() != null && !arrayClass.isEnum()) {
arrayClass = arrayClass.getSuperclass();
}
}
Object[] newArray = (Object[]) Array.newInstance(arrayClass, 1);
newArray[0] = newValue;
newValue = newArray;
}
this.attributes.put(this.attributeName, newValue);
}
代码示例来源:origin: eclipse-vertx/vert.x
public TypedOption<T> setType(Class<T> type) {
this.type = type;
if (type != null && getChoices().isEmpty() && type.isEnum()) {
setChoicesFromEnumType();
}
return this;
}
代码示例来源:origin: prestodb/presto
/**
* Helper method for recognizing `Enum.valueOf()` factory method
*
* @since 2.8.1
*/
protected boolean _isEnumValueOf(AnnotatedWithParams creator) {
return creator.getDeclaringClass().isEnum()
&& "valueOf".equals(creator.getName());
}
代码示例来源:origin: spring-projects/spring-framework
@Override
@Nullable
public String[] getParameterNames(Constructor<?> ctor) {
if (ctor.getDeclaringClass().isEnum() || !KotlinDetector.isKotlinType(ctor.getDeclaringClass())) {
return null;
}
try {
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(ctor);
return (function != null ? getParameterNames(function.getParameters()) : null);
}
catch (UnsupportedOperationException ex) {
return null;
}
}
代码示例来源:origin: apache/incubator-dubbo
private static JavaBeanDescriptor createDescriptorForSerialize(Class<?> cl) {
if (cl.isEnum()) {
return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_ENUM);
} else if (cl.isArray()) {
return new JavaBeanDescriptor(cl.getComponentType().getName(), JavaBeanDescriptor.TYPE_ARRAY);
} else if (ReflectUtils.isPrimitive(cl)) {
return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_PRIMITIVE);
} else if (Class.class.equals(cl)) {
return new JavaBeanDescriptor(Class.class.getName(), JavaBeanDescriptor.TYPE_CLASS);
} else if (Collection.class.isAssignableFrom(cl)) {
return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_COLLECTION);
} else if (Map.class.isAssignableFrom(cl)) {
return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_MAP);
} else {
return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_BEAN);
}
}
代码示例来源:origin: apache/incubator-dubbo
private static JavaBeanDescriptor createDescriptorForSerialize(Class<?> cl) {
if (cl.isEnum()) {
return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_ENUM);
} else if (cl.isArray()) {
return new JavaBeanDescriptor(cl.getComponentType().getName(), JavaBeanDescriptor.TYPE_ARRAY);
} else if (ReflectUtils.isPrimitive(cl)) {
return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_PRIMITIVE);
} else if (Class.class.equals(cl)) {
return new JavaBeanDescriptor(Class.class.getName(), JavaBeanDescriptor.TYPE_CLASS);
} else if (Collection.class.isAssignableFrom(cl)) {
return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_COLLECTION);
} else if (Map.class.isAssignableFrom(cl)) {
return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_MAP);
} else {
return new JavaBeanDescriptor(cl.getName(), JavaBeanDescriptor.TYPE_BEAN);
}
}
内容来源于网络,如有侵权,请联系作者删除!