Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

projections are not allowed for immediate subtypes of a supertype

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?

like image 512
John Smith Avatar asked Dec 18 '16 15:12

John Smith


1 Answers

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>() {
    // ...
}
like image 91
hotkey Avatar answered Sep 23 '22 00:09

hotkey