of Class
fun ofClass(clazz: Class<*>, arguments: List<KotlinTypeToken<*>> = listOf()): KotlinTypeToken<*>(source)
Creates a KotlinTypeToken constructed by a clazz, followed by its type arguments.
This is typically needed when the type token cannot be created at compile time, where instead, you would be creating a subclass of KotlinTypeToken.
Example
public static <V> KotlinTypeToken<Map<String, V>> createMapTypeToken(Class<V> valueType) {
return (KotlinTypeToken<Map<String, V>>) KotlinTypeToken.ofClass(Map.class, List.of(String.class, valueType));
}
Content copied to clipboard
As you can see, this cannot guarantee type safety, you must take care of passing the right number of arguments.