abstract class Base<T : Any>(val clazz: KClass<T>)
class Foo; class Bar;
object A : Base<Foo>(Foo::class) { ... }
object B : Base<Bar>(Bar::class) { ... }
Can I somehow 'reifine' the `T`paramater so I only have to write the parameter class once, e.g. `Base<Foo>()`or
Base(Foo::class)
?
Edit: OK, it's fine that it's possible but I actually meant to ask 'how' to do that. The 2 ways I suggested above do not compile, nor can I use `reified`modifier.
👌 2
k
kqr
01/02/2022, 7:43 PM
@turansky@Guilherme D. Fernandes hm?
t
turansky
01/03/2022, 12:03 AM
Copy code
inline <reified T> fun Base(): Base<T> =
Base(T::class)
🙇♂️ 1
➕ 1
m
mcpiroman
01/07/2022, 1:33 PM
@turansky That does not work
Copy code
abstract class Base<T : Any>(val clazz: KClass<T>)
inline fun<reified T : Any> Base2(): Base<T> = Base(T::class) // Cannot create an instance of an abstract class
class Foo;
object A : Base2<Foo>() // You can't extend from an invocation of function