public abstract class BasicTypesCompatibilityChecker extends Object
| Modifier and Type | Field and Description |
|---|---|
private static Map<Class<?>,Class<?>> |
MAP_BASIC_TYPE2WRAPPER
Maps basic classes to the corresponding wrapper classes.
|
private static Map<Class<?>,Class<?>> |
MAP_WRAPPER2BASIC_TYPE
Maps wrapper classes to the corresponding basic classes.
|
| Constructor and Description |
|---|
BasicTypesCompatibilityChecker() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
areCompatible(Class<?> cls,
Object obj)
Decides whether the given class and object are compatible.
|
static Class<?> |
getWrappedCls(Class<?> cls,
boolean allowsVoid)
Maps a wrapper class
cls to wrapped primitive class. |
static Class<?> |
getWrapperCls(Class<?> cls,
boolean allowsVoid)
Maps a primitive class
cls
to the corresponding wrapper class. |
static boolean |
isPrimitive(Class<?> cls)
Returns whether
cls represents a primitive type. |
static boolean |
wrapsPrimitive(Class<?> cls)
Returns whether
cls represents a type
wrapping a primitive type. |
private static final Map<Class<?>,Class<?>> MAP_WRAPPER2BASIC_TYPE
Void.TYPE is mapped to itself.areCompatible(Class, Object)private static final Map<Class<?>,Class<?>> MAP_BASIC_TYPE2WRAPPER
Void.TYPE is mapped to itself.(Class, Object)public static boolean isPrimitive(Class<?> cls)
cls represents a primitive type.
Note that also Void.TYPE is a primitive type.
An implementation of Class.isPrimitive().cls represents a primitive type.wrapsPrimitive(Class)public static boolean wrapsPrimitive(Class<?> cls)
cls represents a type
wrapping a primitive type.
As an example Integer wraps int and
Void.TYPE wraps itself.cls wraps a primitive type.isPrimitive(Class)public static boolean areCompatible(Class<?> cls, Object obj)
cls - a Class (of course not null).obj - an Object including null.true if and only if either of the following holds:
cls does not refer to a primitive type
and obj may be casted to cls, i.e.
if either obj == null
or (sequentially) cls.isInstance(obj).
cls refers to a primitive type
and (sequentially) obj != null
and obj.getClass()
is the corresponding wrapper type.
MAP_WRAPPER2BASIC_TYPEpublic static Class<?> getWrappedCls(Class<?> cls, boolean allowsVoid)
cls to wrapped primitive class.cls - some Class object.allowsVoid - whether Void.TYPE is wrapped by itself.cls
if cls is the wrapper of a primitive type.
Note that Void.TYPE may be wrapped by itself.IllegalArgumentException - if cls wraps no primitive type
or if cls is Void.TYPE
but this is not allowed by allowsVoid.public static Class<?> getWrapperCls(Class<?> cls, boolean allowsVoid)
cls
to the corresponding wrapper class.cls - some Class object.allowsVoid - whether Void.TYPE wraps itself.cls
if cls is a primitive type.
Note that Void.TYPE may wrap itself.IllegalArgumentException - if cls is no primitive type
or if cls is Void.TYPE
but this is not allowed by allowsVoid.Copyright © 2012–2018 Simuline Organization (l2r). All rights reserved.