java.lang.Object
io.jooby.Reified<T>
- Type Parameters:
T
- Target type.
Represents a generic type
T
. Java doesn't yet provide a way to represent generic types,
so this class does. Forces clients to create a subclass of this class which enables retrieval the
type information even at runtime.
For example, to create a type literal for List<String>
, you can create an empty
anonymous inner class:
Reified<List<String>> list = new Reified<List<String>>() {};
This syntax cannot be used to create type literals that have wildcard parameters, such as
Class<?>
or List<? extends CharSequence>
.
- Author:
- Bob Lee, Sven Mawson, Jesse Wilson
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Reified<CompletableFuture<T>>
completableFuture
(Type type) Creates aCompletableFuture
type literal.final boolean
static <T> Reified<T>
Gets type literal for the givenClass
instance.static Reified<?>
Gets type literal for the givenType
instance.static Reified<?>
getParameterized
(Type rawType, Type... typeArguments) Gets type literal for the parameterized type represented by applyingtypeArguments
torawType
.Returns the raw (non-generic) type for this type.final Type
getType()
Gets underlyingType
instance.final int
hashCode()
Creates aList
type literal.Creates anMap
type literal.Creates anOptional
type literal.static Class<?>
Get raw type (class) from given type.Creates aSet
type literal.final String
toString()
-
Constructor Details
-
Reified
public Reified()Constructs a new type literal. Derives represented class from type parameter.Clients create an empty anonymous subclass. Doing so embeds the type parameter in the anonymous class's type hierarchy so we can reconstitute it at runtime despite erasure.
-
-
Method Details
-
getRawType
Returns the raw (non-generic) type for this type.- Returns:
- Returns the raw (non-generic) type for this type.
-
getType
Gets underlyingType
instance.- Returns:
- Gets underlying
Type
instance.
-
hashCode
public final int hashCode() -
equals
-
toString
-
get
Gets type literal for the givenType
instance.- Parameters:
type
- Source type.- Returns:
- Gets type literal for the given
Type
instance.
-
rawType
Get raw type (class) from given type.- Parameters:
type
- Type.- Returns:
- Raw type.
-
get
Gets type literal for the givenClass
instance.- Type Parameters:
T
- Generic type.- Parameters:
type
- Java type.- Returns:
- Gets type literal for the given
Class
instance.
-
list
Creates aList
type literal.- Type Parameters:
T
- Item type.- Parameters:
type
- Item type.- Returns:
- A
List
type literal.
-
set
Creates aSet
type literal.- Type Parameters:
T
- Item type.- Parameters:
type
- Item type.- Returns:
- A
Set
type literal.
-
optional
Creates anOptional
type literal.- Type Parameters:
T
- Item type.- Parameters:
type
- Item type.- Returns:
- A
Optional
type literal.
-
map
Creates anMap
type literal.- Type Parameters:
K
- Key type.V
- Key type.- Parameters:
key
- Key type.value
- Value type.- Returns:
- A
Map
type literal.
-
completableFuture
Creates aCompletableFuture
type literal.- Type Parameters:
T
- Item type.- Parameters:
type
- Item type.- Returns:
- A
CompletableFuture
type literal.
-
getParameterized
@NonNull public static Reified<?> getParameterized(@NonNull Type rawType, @NonNull Type... typeArguments) Gets type literal for the parameterized type represented by applyingtypeArguments
torawType
.- Parameters:
rawType
- Raw type.typeArguments
- Parameter types.- Returns:
- Gets type literal for the parameterized type represented by applying
typeArguments
torawType
.
-