I have an abstract class like the following:
abstract class AbstractSync<out C : Configuration<*>> : ISync {
internal abstract val configuration: C
...
}
I want another abstract class that inherits from this:
abstract class CascadedSync : AbstractSync {}
The CascadedSync class should not modify the generic parameter C, it should, in fact, only implement a single method of ISync and nothing else.
I am trying out different syntaxes to achive this seemingly simple task. In Java, this would look just like this:
abstract class CascadedSync extends AbstractSync {
}
Translating it to Kotlin with the help of IntelliJ produces this:
abstract class CascadedSync : AbstractSync<*>()
But at the same time gives the following error:
projections are not allowed for immediate subtypes of a supertype
What is the right syntax?
In Kotlin, unlike Java, type parameters are not implicitly copied from types to their subtypes and, even if you don't modify them, they should be redeclared in the subtype declaration:
abstract class CascadedSync<out C : Configuration<*>> : AbstractSync<C>() {
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With