Top Description Fields Constructors Methods
com.google.common.primitives

public final Class Primitives

extends Object
Class Inheritance
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkNotNull

Contains static utility methods pertaining to primitive types and their corresponding wrapper types.
Author
Kevin Bourrillion
Since
1.0

Field Summary

Modifier and TypeField and Description
private static final Map<Class<?>, Class<?>>
PRIMITIVE_TO_WRAPPER_TYPE

A map from primitive types to their corresponding wrapper types.

private static final Map<Class<?>, Class<?>>
WRAPPER_TO_PRIMITIVE_TYPE

A map from wrapper types to their corresponding primitive types.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static void
add(Map<Class<?>, Class<?>> forward, Map<Class<?>, Class<?>> backward, Class<?> key, Class<?> value)

public static Set<Class<?>>
allPrimitiveTypes()

Returns an immutable set of all nine primitive types (including void).

public static Set<Class<?>>
allWrapperTypes()

Returns an immutable set of all nine primitive-wrapper types (including Void).

public static boolean
isWrapperType(Class<?> type)

Returns true if type is one of the nine primitive-wrapper types, such as Integer.

public static <T> Class<T>
unwrap(Class<T> type)

Returns the corresponding primitive type of type if it is a wrapper type; otherwise returns type itself.

public static <T> Class<T>
wrap(Class<T> type)

Returns the corresponding wrapper type of type if it is a primitive type; otherwise returns type itself.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

PRIMITIVE_TO_WRAPPER_TYPEback to summary
private static final Map<Class<?>, Class<?>> PRIMITIVE_TO_WRAPPER_TYPE

A map from primitive types to their corresponding wrapper types.

WRAPPER_TO_PRIMITIVE_TYPEback to summary
private static final Map<Class<?>, Class<?>> WRAPPER_TO_PRIMITIVE_TYPE

A map from wrapper types to their corresponding primitive types.

Constructor Detail

Primitivesback to summary
private Primitives()

Method Detail

addback to summary
private static void add(Map<Class<?>, Class<?>> forward, Map<Class<?>, Class<?>> backward, Class<?> key, Class<?> value)
allPrimitiveTypesback to summary
public static Set<Class<?>> allPrimitiveTypes()

Returns an immutable set of all nine primitive types (including void). Note that a simpler way to test whether a Class instance is a member of this set is to call Class#isPrimitive.

Since
3.0
allWrapperTypesback to summary
public static Set<Class<?>> allWrapperTypes()

Returns an immutable set of all nine primitive-wrapper types (including Void).

Since
3.0
isWrapperTypeback to summary
public static boolean isWrapperType(Class<?> type)

Returns true if type is one of the nine primitive-wrapper types, such as Integer.

See Also
Class#isPrimitive
unwrapback to summary
public static <T> Class<T> unwrap(Class<T> type)

Returns the corresponding primitive type of 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
wrapback to summary
public static <T> Class<T> wrap(Class<T> type)

Returns the corresponding wrapper type of 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