public class TypeMagic
extends java.lang.Object
| Constructor and Description |
|---|
TypeMagic() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.Class<?> |
classForType(java.lang.reflect.Type t)
This is a surprisingly intractable problem in Java: "Type" pretty much represents all possible states of reified
and unreified type information, and each kind of Type has different, mutually exclusive, and often unintended
ways of uncovering its (un-reified) class.
|
static <U> U |
createAndCast(java.lang.Class<U> t,
boolean failFast)
Attempts to create a new instance of the specified class using its no-arg constructor, if it has one.
|
static <U> U |
createAndCast(java.lang.reflect.Type t)
Attempts to create a new instance of type t, and (unsafely) cast it to the target type U.
|
static <U> U |
createAndCastCarefully(java.lang.reflect.Type t) |
static <T> T |
shoehorn(java.lang.Object o)
Extremely unsafely casts an object into another type.
|
@Nullable public static java.lang.Class<?> classForType(java.lang.reflect.Type t)
Generally it's much safer to use this for the type from a *field* than a blind type from an argument.
@Nullable public static <U> U createAndCast(java.lang.reflect.Type t)
U - the target type.t - the source type. The object will be created as this type.public static <U> U createAndCastCarefully(java.lang.reflect.Type t)
throws DeserializationException
DeserializationException@Nullable
public static <U> U createAndCast(java.lang.Class<U> t,
boolean failFast)
throws DeserializationException
U - the target type.t - the source type. The object will be created as this type.DeserializationExceptionpublic static <T> T shoehorn(java.lang.Object o)
T - the destination typeo - the source object, of any type