java.lang.Object
com.github.mizosoft.methanol.TypeRef<T>
- Type Parameters:
T
- represents the type this object holds a reference to
A generic object that holds a reference to the
Type
of its generic argument T
.
This class utilizes the supertype-token idiom, which is used to capture complex types (e.g.
List<String>
) that are otherwise impossible to represent using ordinary Class
objects.-
Constructor Summary
ModifierConstructorDescriptionprotected
TypeRef()
Creates a newTypeRef<T>
capturing theType
ofT
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returnstrue
if the given object is aTypeRef
and both instances represent the same type.Returns the underlying type as aClass<T>
for when it is known thatTypeRef
is already raw.static <U> TypeRef
<U> Deprecated.static TypeRef
<?> Deprecated.in favor of the better-namedof(Type)
.int
hashCode()
static <U> TypeRef
<U> Creates a newTypeRef
from the given class.static TypeRef
<?> Deprecated.rawType()
Returns theClass<? super T>
that represents the resolved raw type ofT
.toString()
Returns a string representation for the type.final Type
type()
Returns the underlyingType
.
-
Constructor Details
-
TypeRef
protected TypeRef()Creates a newTypeRef<T>
capturing theType
ofT
. This constructor is typically invoked as an anonymous class expression (e.g.new TypeRef<List<String>>() {}
).- Throws:
IllegalStateException
- if the raw version of this class is used
-
-
Method Details
-
type
Returns the underlyingType
. -
rawType
Returns theClass<? super T>
that represents the resolved raw type ofT
. The returned class isClass<? super T>
becauseT
can possibly be a generic type, and it is not semantically correct for aClass
to be parameterized with such.- See Also:
-
exactRawType
Returns the underlying type as aClass<T>
for when it is known thatTypeRef
is already raw. Similar to(Class<T>) typeRef.type()
.- Throws:
UnsupportedOperationException
- if the underlying type is not a raw type
-
equals
Returnstrue
if the given object is aTypeRef
and both instances represent the same type. -
hashCode
public int hashCode() -
toString
Returns a string representation for the type. -
from
Deprecated.in favor of the better-namedof(Type)
.Creates a newTypeRef
for the given type.- Throws:
IllegalArgumentException
- if the given type is not a standard specialization ofType
-
of
Deprecated.Creates a newTypeRef
for the given type.- Throws:
IllegalArgumentException
- if the given type is not a standard specialization ofType
-
from
Deprecated.in favor of the better-namedof(Class)
Creates a newTypeRef
from the given class. -
of
Creates a newTypeRef
from the given class.
-
of(Class)