Caleb B
02/24/2025, 3:58 PMMap<Class<T>, Supplier<T>>
, where T
is NOT a type parameter of the enclosing class but instead "pinning" the type of the supplier to the type of the class for runtime type validation? Instead of Map<Class<*>, Supplier<*>>
and having to suppress constant type coercion warningsSam
02/24/2025, 4:01 PMtypealias MyThing<T> = Map<Class<T>, Supplier<T>>
Caleb B
02/24/2025, 4:02 PMSam
02/24/2025, 4:03 PMCaleb B
02/24/2025, 4:03 PMget(Foo::class)
, I know that the result will always be a Supplier<Foo>
, but there's no way to specify that I know ofSam
02/24/2025, 4:06 PMMap
, and I don't know of any other built-in type that does it, but it's easy enough to express it in the type system:
interface SupplierMap {
fun <T> get(type: KClass<T>): Supplier<T>
}