Package com.google.common.primitives
Class Primitives
java.lang.Object
com.google.common.primitives.Primitives
Contains static utility methods pertaining to primitive types and their corresponding wrapper
types.
- Since:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionA map from primitive types to their corresponding wrapper types.A map from wrapper types to their corresponding primitive types. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
Returns an immutable set of all nine primitive types (includingvoid
).Returns an immutable set of all nine primitive-wrapper types (includingVoid
).static boolean
isWrapperType
(Class<?> type) static <T> Class
<T> Returns the corresponding primitive type oftype
if it is a wrapper type; otherwise returnstype
itself.static <T> Class
<T> Returns the corresponding wrapper type oftype
if it is a primitive type; otherwise returnstype
itself.
-
Field Details
-
PRIMITIVE_TO_WRAPPER_TYPE
A map from primitive types to their corresponding wrapper types. -
WRAPPER_TO_PRIMITIVE_TYPE
A map from wrapper types to their corresponding primitive types.
-
-
Constructor Details
-
Primitives
private Primitives()
-
-
Method Details
-
add
-
allPrimitiveTypes
Returns an immutable set of all nine primitive types (includingvoid
). Note that a simpler way to test whether aClass
instance is a member of this set is to callClass.isPrimitive()
.- Since:
- 3.0
-
allWrapperTypes
Returns an immutable set of all nine primitive-wrapper types (includingVoid
).- Since:
- 3.0
-
isWrapperType
- See Also:
-
wrap
Returns the corresponding wrapper type oftype
if it is a primitive type; otherwise returnstype
itself. Idempotent.wrap(int.class) == Integer.class wrap(Integer.class) == Integer.class wrap(String.class) == String.class
-
unwrap
Returns the corresponding primitive type oftype
if it is a wrapper type; otherwise returnstype
itself. Idempotent.unwrap(Integer.class) == int.class unwrap(int.class) == int.class unwrap(String.class) == String.class
-