ursus
02/16/2024, 1:01 AMYoussef Shoaib [MOD]
02/16/2024, 1:14 AMinline + reifiedursus
02/16/2024, 1:16 AMabtract fun fooType() : Class<T> to override in sublasses, don't I?AdamW
02/16/2024, 2:02 AMursus
02/16/2024, 2:05 AMursus
02/16/2024, 2:06 AMeygraber
02/16/2024, 2:19 AMAdamW
02/16/2024, 2:47 AMursus
02/16/2024, 3:18 PMclass Screen<T> {
fun createViewModel() {
val scopes = Scopes.get(T::class) <----
..
}
}eygraber
02/16/2024, 3:21 PMinline fun <reified T> Screen() = Screen(T::class.java)
class Screen<T>(private val clazz: Class<T>) ...ursus
02/16/2024, 3:22 PMeygraber
02/16/2024, 3:27 PMursus
02/16/2024, 3:28 PMursus
02/16/2024, 3:29 PMclass Screen<T> {
fun foo() {
}
inline reified <T> whatever() -> KClass<T> {
T::class
}
}eygraber
02/16/2024, 3:30 PMT, but if you want to specify T when you invoke whatever that would work (but would be brittle)
You might also have to do an unsafe casteygraber
02/16/2024, 3:32 PMnot sure if it's worth the reflection runtime penalty
You mean
Class.forName (if that's what deserialization is using)? Unless this is a critical section you're probably fine. Not even sure how big of a penalty it is.Johann Pardanaud
02/20/2024, 9:49 AM