public final class Primitives
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.Class<?>,java.lang.Class<?>> |
PRIMITIVE_TO_WRAPPER_TYPE
A map from primitive types to their corresponding wrapper types.
|
private static java.util.Map<java.lang.Class<?>,java.lang.Class<?>> |
WRAPPER_TO_PRIMITIVE_TYPE
A map from wrapper types to their corresponding primitive types.
|
Modifier | Constructor and Description |
---|---|
private |
Primitives() |
Modifier and Type | Method and Description |
---|---|
private static void |
add(java.util.Map<java.lang.Class<?>,java.lang.Class<?>> forward,
java.util.Map<java.lang.Class<?>,java.lang.Class<?>> backward,
java.lang.Class<?> key,
java.lang.Class<?> value) |
static boolean |
isPrimitive(java.lang.reflect.Type type)
Returns true if this type is a primitive.
|
static boolean |
isWrapperType(java.lang.reflect.Type type)
Returns
true if type is one of the nine
primitive-wrapper types, such as Integer . |
static <T> java.lang.Class<T> |
unwrap(java.lang.Class<T> type)
Returns the corresponding primitive type of
type if it is a
wrapper type; otherwise returns type itself. |
static <T> java.lang.Class<T> |
wrap(java.lang.Class<T> type)
Returns the corresponding wrapper type of
type if it is a primitive
type; otherwise returns type itself. |
private static final java.util.Map<java.lang.Class<?>,java.lang.Class<?>> PRIMITIVE_TO_WRAPPER_TYPE
private static final java.util.Map<java.lang.Class<?>,java.lang.Class<?>> WRAPPER_TO_PRIMITIVE_TYPE
private static void add(java.util.Map<java.lang.Class<?>,java.lang.Class<?>> forward, java.util.Map<java.lang.Class<?>,java.lang.Class<?>> backward, java.lang.Class<?> key, java.lang.Class<?> value)
public static boolean isPrimitive(java.lang.reflect.Type type)
public static boolean isWrapperType(java.lang.reflect.Type type)
true
if type
is one of the nine
primitive-wrapper types, such as Integer
.Class.isPrimitive()
public static <T> java.lang.Class<T> wrap(java.lang.Class<T> type)
type
if it is a primitive
type; otherwise returns type
itself. Idempotent.
wrap(int.class) == Integer.class wrap(Integer.class) == Integer.class wrap(String.class) == String.class
public static <T> java.lang.Class<T> unwrap(java.lang.Class<T> type)
type
if it is a
wrapper type; otherwise returns type
itself. Idempotent.
unwrap(Integer.class) == int.class unwrap(int.class) == int.class unwrap(String.class) == String.class