public final class TypeUtilities extends Object
Modifier and Type | Method | Description |
---|---|---|
static Class |
getPrimitiveType |
When passed a class representing a wrapper for a primitive type, returns the class representing the corresponding primitive type. |
static Class |
getPrimitiveTypeByName |
Given a name of a primitive type returns the class representing it. |
static Class |
getWrapperType |
When passed a class representing a primitive type, returns the class representing the corresponding wrapper type. |
static boolean |
isConvertibleWithoutLoss |
Determines whether a type can be converted to another without losing any precision. |
static boolean |
isMethodInvocationConvertible |
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 |
isSubtype |
Determines whether one type is a subtype of another type, as per JLS 4.10 "Subtyping". |
static boolean |
isWrapperType |
Returns true if the passed type is a wrapper for a primitive type. |
public static boolean isMethodInvocationConvertible(Class<?> sourceType, Class<?> targetType)
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.sourceType
- the type being converted from (call site type for parameter types, method type for return types)targetType
- the parameter type being converted to (method type for parameter types, call site type for return types)public static boolean isConvertibleWithoutLoss(Class<?> sourceType, Class<?> targetType)
Object
(either as null
or as a custom value set in DynamicLinkerFactory.setAutoConversionStrategy(MethodTypeConversionStrategy)
). Somewhat unintuitively, we consider anything to be convertible to void even though converting to void causes the ultimate loss of data. On the other hand, conversion to void essentially means that the value is of no interest and should be discarded, thus there's no expectation of preserving any precision.sourceType
- the source typetargetType
- the target typepublic 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 type.public 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 typepublic static boolean isWrapperType(Class<?> type)
type
- the examined type
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/jdk.dynalink/jdk/dynalink/linker/support/TypeUtilities.html