本文整理了Java中java.lang.Class.isPrimitive()
方法的一些代码示例,展示了Class.isPrimitive()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Class.isPrimitive()
方法的具体详情如下:
包路径:java.lang.Class
类名称:Class
方法名:isPrimitive
[英]Tests whether this Class represents a primitive type.
[中]测试此类是否表示基元类型。
代码示例来源:origin: google/guava
/**
* Returns true if this type is one of the nine primitive types (including {@code void}).
*
* @since 15.0
*/
public final boolean isPrimitive() {
return (runtimeType instanceof Class) && ((Class<?>) runtimeType).isPrimitive();
}
代码示例来源:origin: apache/incubator-dubbo
private static boolean isPrimitive(Class<?> cls) {
return cls.isPrimitive() || cls == Boolean.class || cls == Byte.class
|| cls == Character.class || cls == Short.class || cls == Integer.class
|| cls == Long.class || cls == Float.class || cls == Double.class
|| cls == String.class || cls == Date.class || cls == Class.class;
}
代码示例来源:origin: apache/incubator-dubbo
private static boolean isPrimitive(Class<?> cls) {
return cls.isPrimitive() || cls == Boolean.class || cls == Byte.class
|| cls == Character.class || cls == Short.class || cls == Integer.class
|| cls == Long.class || cls == Float.class || cls == Double.class
|| cls == String.class || cls == Date.class || cls == Class.class;
}
代码示例来源:origin: apache/incubator-dubbo
public static boolean isPrimitive(Class<?> type) {
return type.isPrimitive()
|| type == String.class
|| type == Character.class
|| type == Boolean.class
|| type == Byte.class
|| type == Short.class
|| type == Integer.class
|| type == Long.class
|| type == Float.class
|| type == Double.class
|| type == Object.class;
}
代码示例来源:origin: apache/incubator-dubbo
public static boolean isPrimitive(Class<?> type) {
return type.isPrimitive()
|| type == String.class
|| type == Character.class
|| type == Boolean.class
|| type == Byte.class
|| type == Short.class
|| type == Integer.class
|| type == Long.class
|| type == Float.class
|| type == Double.class
|| type == Object.class;
}
代码示例来源:origin: square/retrofit
static void checkNotPrimitive(Type type) {
if (type instanceof Class<?> && ((Class<?>) type).isPrimitive()) {
throw new IllegalArgumentException();
}
}
代码示例来源:origin: google/guava
private static void disallowPrimitiveType(Type[] types, String usedAs) {
for (Type type : types) {
if (type instanceof Class) {
Class<?> cls = (Class<?>) type;
checkArgument(!cls.isPrimitive(), "Primitive type '%s' used as %s", cls, usedAs);
}
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Resolve the given class if it is a primitive class,
* returning the corresponding primitive wrapper type instead.
* @param clazz the class to check
* @return the original class, or a primitive wrapper for the original primitive type
*/
public static Class<?> resolvePrimitiveIfNecessary(Class<?> clazz) {
Assert.notNull(clazz, "Class must not be null");
return (clazz.isPrimitive() && clazz != void.class ? primitiveTypeToWrapperMap.get(clazz) : clazz);
}
代码示例来源:origin: apache/incubator-dubbo
private static boolean isPrimitive(Class<?> cls) {
return cls.isPrimitive() || cls == String.class || cls == Boolean.class || cls == Character.class
|| Number.class.isAssignableFrom(cls) || Date.class.isAssignableFrom(cls);
}
代码示例来源:origin: apache/incubator-dubbo
public static boolean isPrimitive(Class<?> cls) {
return cls.isPrimitive() || cls == String.class || cls == Boolean.class || cls == Character.class
|| Number.class.isAssignableFrom(cls) || Date.class.isAssignableFrom(cls);
}
代码示例来源:origin: apache/incubator-dubbo
private static boolean isPrimitive(Class<?> cls) {
return cls.isPrimitive() || cls == String.class || cls == Boolean.class || cls == Character.class
|| Number.class.isAssignableFrom(cls) || Date.class.isAssignableFrom(cls);
}
代码示例来源:origin: apache/incubator-dubbo
public static boolean isPrimitive(Class<?> cls) {
return cls.isPrimitive() || cls == String.class || cls == Boolean.class || cls == Character.class
|| Number.class.isAssignableFrom(cls) || Date.class.isAssignableFrom(cls);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Check if the given class represents an array of primitives,
* i.e. boolean, byte, char, short, int, long, float, or double.
* @param clazz the class to check
* @return whether the given class is a primitive array class
*/
public static boolean isPrimitiveArray(Class<?> clazz) {
Assert.notNull(clazz, "Class must not be null");
return (clazz.isArray() && clazz.getComponentType().isPrimitive());
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Is this type a primitive type?
*/
public boolean isPrimitive() {
return getType().isPrimitive();
}
代码示例来源:origin: spring-projects/spring-framework
private int countNumberOfUnboundPrimitiveArguments() {
int count = 0;
for (int i = 0; i < this.argumentTypes.length; i++) {
if (isUnbound(i) && this.argumentTypes[i].isPrimitive()) {
count++;
}
}
return count;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Check if the given class represents a primitive (i.e. boolean, byte,
* char, short, int, long, float, or double) or a primitive wrapper
* (i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double).
* @param clazz the class to check
* @return whether the given class is a primitive or primitive wrapper class
*/
public static boolean isPrimitiveOrWrapper(Class<?> clazz) {
Assert.notNull(clazz, "Class must not be null");
return (clazz.isPrimitive() || isPrimitiveWrapper(clazz));
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Determine if the given type is assignable from the given value,
* assuming setting by reflection. Considers primitive wrapper classes
* as assignable to the corresponding primitive types.
* @param type the target type
* @param value the value that should be assigned to the type
* @return if the type is assignable from the value
*/
public static boolean isAssignableValue(Class<?> type, @Nullable Object value) {
Assert.notNull(type, "Type must not be null");
return (value != null ? isAssignable(type, value.getClass()) : !type.isPrimitive());
}
代码示例来源:origin: google/guava
static boolean isPrimitiveOrNullable(Parameter param) {
return param.getType().getRawType().isPrimitive() || isNullable(param);
}
代码示例来源:origin: apache/incubator-dubbo
@Override
protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException {
Class<?> clazz = desc.forClass();
if (clazz.isPrimitive() || clazz.isArray()) {
write(0);
super.writeClassDescriptor(desc);
} else {
write(1);
writeUTF(desc.getName());
}
}
}
代码示例来源:origin: apache/incubator-dubbo
@Override
protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException {
Class<?> clazz = desc.forClass();
if (clazz.isPrimitive() || clazz.isArray()) {
write(0);
super.writeClassDescriptor(desc);
} else {
write(1);
writeUTF(desc.getName());
}
}
}
内容来源于网络,如有侵权,请联系作者删除!