How to specify that the type parameters of a class have to inherit the class itself? ( class A<T : A>{ __ } ) | Kotlin

i have an abstract class with a type parameter:

abstract class AClass<T>(){ ___ }

however, i want to specify that the type T must be a child of AClass itself.

abstract class AClass<T : AClass>(){ ___ }

this doesnt work. I also tried:

abstract class AClass<T : AClass<*>>(){ ___ }

but the IDE gives me a “Finite Bound Restriction” Error.

Is it even possible to achieve the desired behaviour in Kotlin?

Do you mean this?

abstract class AClass<T : AClass<T>>
1 Like