-
public abstract class TypeToken<T extends Object>A container for a generic type.
Java Usage:
Type type = new TypeToken<List<Foo>>() {}.get(); // type == List<Foo> AnnotatedType type = new TypeToken<List<@TypeAnnotation Foo>>() {}.getAnnotated(); // type == List<@TypeAnnotation Foo>Kotlin usage:
val type = object : TypeToken<List<Foo>>() {}.get() val type = typeToken<List<Foo>>() // or the helper functionNOTE!! Due to a bug in javac before JDK 10, in most cases annotated type tokens will not work. https://github.com/raphw/byte-buddy/issues/583
NOTE!! As of Kotlin 1.4, Java type annotations are finally supported, though in a limited fashion and gated behind a compiler flag. (more info here)
-
-
Constructor Summary
Constructors Constructor Description TypeToken()
-
Method Summary
Modifier and Type Method Description final Typeget()Gets the generic type represented by this TypeToken final AnnotatedTypegetAnnotated()Gets the annotated type represented by this TypeToken final KTypeProjectiongetKotlin()Gets the kotlin type represented by this TypeToken -
-
Method Detail
-
getAnnotated
final AnnotatedType getAnnotated()
Gets the annotated type represented by this TypeToken
-
getKotlin
final KTypeProjection getKotlin()
Gets the kotlin type represented by this TypeToken
-
-
-
-