Class TypeUtilities
java.lang.Object
jdk.dynalink.linker.support.TypeUtilities
Various static utility methods for working with Java types.
- Since:
- 9
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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 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 booleanisConvertibleWithoutLoss(Class<?> sourceType, Class<?> targetType) Determines whether a type can be converted to another without losing any precision.static booleanisMethodInvocationConvertible(Class<?> sourceType, Class<?> targetType) Determines whether one type can be converted to another type using a method invocation conversion, as per JLS 5.3 "Method Invocation Conversion".static booleanDetermines whether one type is a subtype of another type, as per JLS 4.10 "Subtyping".static booleanisWrapperType(Class<?> type) Returns true if the passed type is a wrapper for a primitive type.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.toString()Answers a string containing a concise, human-readable description of the receiver.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
Method Details
-
isMethodInvocationConvertible
Determines whether one type can be converted to another type using a method invocation conversion, as per JLS 5.3 "Method Invocation Conversion". This is basically all conversions allowed by subtyping (seeisSubtype(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.- Parameters:
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)- Returns:
- true if source type is method invocation convertible to target type.
-
isConvertibleWithoutLoss
Determines whether a type can be converted to another without losing any precision. As a special case, void is considered convertible only to void andObject(either asnullor as a custom value set inDynamicLinkerFactory.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.- Parameters:
sourceType- the source typetargetType- the target type- Returns:
- true if lossless conversion is possible
-
isSubtype
Determines whether one type is a subtype of another type, as per JLS 4.10 "Subtyping". Note: this is not strict or proper subtype, therefore true is also returned for identical types; to be completely precise, it allows identity conversion (JLS 5.1.1), widening primitive conversion (JLS 5.1.2) and widening reference conversion (JLS 5.1.5).- Parameters:
subType- the supposed subtypesuperType- the supposed supertype of the subtype- Returns:
- true if subType can be converted by identity conversion, widening primitive conversion, or widening reference conversion to superType.
-
getPrimitiveTypeByName
Given a name of a primitive type returns the class representing it. I.e. when invoked with "int", returnsInteger.TYPE.- Parameters:
name- the name of the primitive type- Returns:
- the class representing the primitive type, or null if the name does not correspond to a primitive type.
-
getPrimitiveType
When passed a class representing a wrapper for a primitive type, returns the class representing the corresponding primitive type. I.e. calling it withInteger.classwill returnInteger.TYPE. If passed a class that is not a wrapper for primitive type, returns null.- Parameters:
wrapperType- the class object representing a wrapper for a primitive type.- Returns:
- the class object representing the primitive type, or null if the passed class is not a primitive wrapper.
-
getWrapperType
When passed a class representing a primitive type, returns the class representing the corresponding wrapper type. I.e. calling it withint.classwill returnInteger.class. If passed a class that is not a primitive type, returns null.- Parameters:
primitiveType- the class object representing a primitive type- Returns:
- the class object representing the wrapper type, or null if the passed class is not a primitive.
-
isWrapperType
Returns true if the passed type is a wrapper for a primitive type.- Parameters:
type- the examined type- Returns:
- true if the passed type is a wrapper for a primitive type.
-