public final class PrimitiveTypes
extends java.lang.Object
Class<?> objects that Java reflection treats as primitive,
which includes primitive types and void. Provides conversion from primitive type names
(and "void") to Class objects, boxing and unboxing, as well as primitive subtype and
assignment tests.| Modifier and Type | Field and Description |
|---|---|
private static java.util.Map<java.lang.Class<?>,java.lang.Class<?>> |
boxedToPrimitive
Map from boxed primitive to primitive
Class<?> objects. |
private static java.util.Map<java.lang.String,java.lang.Class<?>> |
nameToClass
Map from primitive type name (and "void") to
Class<?> objects. |
private static java.util.Map<java.lang.Class<?>,java.lang.Class<?>> |
primitiveToBoxed
Map from primitive to boxed primitive
Class<?> objects. |
private static java.util.Map<java.lang.Class<?>,java.util.Set<java.lang.Class<?>>> |
wideningTable
Primitive widening map.
|
| Modifier | Constructor and Description |
|---|---|
private |
PrimitiveTypes() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.Class<?> |
classForName(java.lang.String typeName)
Return the
Class<?> object for the given primitive type name or "void". |
(package private) static boolean |
isAssignable(java.lang.Class<?> target,
java.lang.Class<?> source)
Tests assignability from source to target type via identity conversion and widening primitive
conversion.
|
static boolean |
isBoxedPrimitive(java.lang.Class<?> c)
Determine if the given
Class<?> is a boxed primitive type. |
static boolean |
isSubtype(java.lang.Class<?> first,
java.lang.Class<?> second)
Indicates whether the first primitive type is a (transitive) subtype of the second primitive as
determined by primitive widening.
|
static java.lang.Class<?> |
toBoxedType(java.lang.Class<?> cls)
Return boxed type for a primitive type.
|
static java.lang.Class<?> |
toUnboxedType(java.lang.Class<?> c)
Returns the primitive
Class<?> type for a boxed primitive type. |
private static final java.util.Map<java.lang.Class<?>,java.lang.Class<?>> boxedToPrimitive
Class<?> objects.private static final java.util.Map<java.lang.Class<?>,java.lang.Class<?>> primitiveToBoxed
Class<?> objects.private static final java.util.Map<java.lang.String,java.lang.Class<?>> nameToClass
Class<?> objects.private static final java.util.Map<java.lang.Class<?>,java.util.Set<java.lang.Class<?>>> wideningTable
public static java.lang.Class<?> classForName(java.lang.String typeName)
Class<?> object for the given primitive type name or "void". These are names
that Class.forName() will not convert.typeName - the name of the typeClass<?> object for the type, or nullstatic boolean isAssignable(java.lang.Class<?> target,
java.lang.Class<?> source)
target - the target type for assignment; that is, the lvalue or left-hand side. Must be
primitive.source - the source type for assignment; that is, the rvalue or right-hand side. Must be
primitive.public static boolean isBoxedPrimitive(java.lang.Class<?> c)
Class<?> is a boxed primitive type.c - the Class<?>Class<?> is a boxed primitive, false otherwisepublic static boolean isSubtype(java.lang.Class<?> first,
java.lang.Class<?> second)
first - the first primitive typesecond - the second primitive typepublic static java.lang.Class<?> toBoxedType(java.lang.Class<?> cls)
cls - the Class object for the primitive typepublic static java.lang.Class<?> toUnboxedType(java.lang.Class<?> c)
Class<?> type for a boxed primitive type.c - the Class<?> type