T
- Target type.public class Reified<T> extends Object
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>
.
Constructor and Description |
---|
Reified()
Constructs a new type literal.
|
Modifier and Type | Method and Description |
---|---|
static <T> Reified<CompletableFuture<T>> |
completableFuture(Type type)
Creates a
CompletableFuture type literal. |
boolean |
equals(Object o) |
static <T> Reified<T> |
get(Class<T> type)
Gets type literal for the given
Class instance. |
static Reified<?> |
get(Type type)
Gets type literal for the given
Type instance. |
static Reified<?> |
getParameterized(Type rawType,
Type... typeArguments)
Gets type literal for the parameterized type represented by applying
typeArguments to
rawType . |
Class<? super T> |
getRawType()
Returns the raw (non-generic) type for this type.
|
Type |
getType()
Gets underlying
Type instance. |
int |
hashCode() |
static <T> Reified<List<T>> |
list(Type type)
Creates a
List type literal. |
static <K,V> Reified<Map<K,V>> |
map(Type key,
Type value)
Creates an
Map type literal. |
static <T> Reified<Optional<T>> |
optional(Type type)
Creates an
Optional type literal. |
static Class<?> |
rawType(Type type)
Get raw type (class) from given type.
|
static <T> Reified<Set<T>> |
set(Type type)
Creates a
Set type literal. |
String |
toString() |
public Reified()
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.
@Nonnull public final Class<? super T> getRawType()
@Nonnull public final Type getType()
Type
instance.Type
instance.@Nonnull public static Reified<?> get(@Nonnull Type type)
Type
instance.type
- Source type.Type
instance.@Nonnull public static Class<?> rawType(@Nonnull Type type)
type
- Type.@Nonnull public static <T> Reified<T> get(@Nonnull Class<T> type)
Class
instance.T
- Generic type.type
- Java type.Class
instance.@Nonnull public static <T> Reified<List<T>> list(@Nonnull Type type)
List
type literal.T
- Item type.type
- Item type.List
type literal.@Nonnull public static <T> Reified<Set<T>> set(@Nonnull Type type)
Set
type literal.T
- Item type.type
- Item type.Set
type literal.@Nonnull public static <T> Reified<Optional<T>> optional(@Nonnull Type type)
Optional
type literal.T
- Item type.type
- Item type.Optional
type literal.@Nonnull public static <K,V> Reified<Map<K,V>> map(@Nonnull Type key, @Nonnull Type value)
Map
type literal.K
- Key type.V
- Key type.key
- Key type.value
- Value type.Map
type literal.@Nonnull public static <T> Reified<CompletableFuture<T>> completableFuture(@Nonnull Type type)
CompletableFuture
type literal.T
- Item type.type
- Item type.CompletableFuture
type literal.@Nonnull public static Reified<?> getParameterized(@Nonnull Type rawType, @Nonnull Type... typeArguments)
typeArguments
to
rawType
.rawType
- Raw type.typeArguments
- Parameter types.typeArguments
to rawType
.Copyright © 2022. All rights reserved.