Here I found many similar questions, but not one solution did not help me because of the specifics of my problem. I have the following class hierarchy:
com.package.ParentInterface.java
public interface ParentInterface {
void setMessages(Collection<String> var1);
}
com.package.ParentClass.java
public class ParentClass {
protected Collection messages;
public void setMessages(Collection messages)
{
this.messages = messages;
}
}
com.package.ChildClass.java
public class ChildClass extends ParentClass implements ParentInterface {
}
com.package.KotlinClass.kt
class KotlinClass: ChildClass()
In the last Kotlin class I have following error: `Class 'KotlinClass' is not abstract and does not implement base class member public abstract fun setMessages(var1: (Mutable)Collection!): Unit defined in com.package.ChildClass.
When I accept the proposal of generating a method implementation using the IDE, I have:
override fun setMessages(var1: MutableCollection<String>?) {
}
and I get the following error on the generated method:
Accidental override: The following declarations have the same JVM signature (setMessages(Ljava/util/Collection;)V):
- public open fun setMessages(messages: (MutableCollection..Collection<*>?)): Unit defined in com.package.KotlinClass
- public open fun setMessages(var1: MutableCollection?): Unit defined in com.package.KotlinClass
And I can only change KotlinClass, because other classes are classes of a third-party library in Java. Help someone, please, I have already spent a lot of time on this problem.
ParentClass
uses a rawCollection
(i.e. one without a type argument). That's a language features meant exclusively for backwards compatibility with pre-generics code and you should absolutely avoid using it. I wouldn't be surprised if Kotlin reacted very badly to such code, as it basically breaks the type system. – Joachim SauerChildClass extends ParentClass implements ParentInterface
seems like an error.ParentClass implements ParentInterface
seems more valid to me. And removing theimplements ParentInterface
fromChildClass
would solve the problem. – Lino