public class TypeUtilities extends Object
Modifier and Type | Method and Description |
---|---|
static Class<?> |
getMostSpecificCommonType(Class<?> c1,
Class<?> c2)
Given two types represented by c1 and c2, returns a type that is their most specific common superclass or
superinterface.
|
static Class<?> |
getPrimitiveType(Class<?> wrapperType)
When passed a class representing a wrapper for a primitive type, returns the class representing the corresponding
primitive type.
|
static Class<?> |
getPrimitiveTypeByName(String name)
Given a name of a primitive type (except "void"), returns the class representing it.
|
static Class<?> |
getWrapperType(Class<?> primitiveType)
When passed a class representing a primitive type, returns the class representing the corresponding
wrapper type.
|
static boolean |
isMethodInvocationConvertible(Class<?> callSiteType,
Class<?> methodType)
Determines whether one type can be converted to another type using a method invocation conversion, as per JLS 5.3
"Method Invocation Conversion".
|
static boolean |
isPotentiallyConvertible(Class<?> callSiteType,
Class<?> methodType)
Determines whether one type can be potentially converted to another type at runtime.
|
static boolean |
isSubtype(Class<?> subType,
Class<?> superType)
Determines whether one type is a subtype of another type, as per JLS 4.10 "Subtyping".
|
public static Class<?> getMostSpecificCommonType(Class<?> c1, Class<?> c2)
c1
- one typec2
- another typeObject
is returned.public static boolean isMethodInvocationConvertible(Class<?> callSiteType, Class<?> methodType)
isSubtype(Class, Class)
) as well as boxing conversion (JLS 5.1.7) optionally followed by widening
reference conversion and unboxing conversion (JLS 5.1.8) optionally followed by widening primitive conversion.callSiteType
- the parameter type at the call sitemethodType
- the parameter type in the method declarationpublic static boolean isPotentiallyConvertible(Class<?> callSiteType, Class<?> methodType)
callSiteType
- the parameter type at the call sitemethodType
- the parameter type in the method declarationpublic static boolean isSubtype(Class<?> subType, Class<?> superType)
subType
- the supposed subtypesuperType
- the supposed supertype of the subtypepublic static Class<?> getPrimitiveTypeByName(String name)
Integer.TYPE
.name
- the name of the primitive typepublic static Class<?> getPrimitiveType(Class<?> wrapperType)
Integer.class
will return Integer.TYPE
. If passed a class
that is not a wrapper for primitive type, returns null.wrapperType
- the class object representing a wrapper for a primitive typepublic static Class<?> getWrapperType(Class<?> primitiveType)
int.class
will return Integer.class
. If passed a class
that is not a primitive type, returns null.primitiveType
- the class object representing a primitive typeCopyright © 2018 Attila Szegedi. All rights reserved.