0

I have the following classes and interface:

class A() {
    fun one() {...}
    fun two() {...}
}

class B(): A, C {
    fun tree() {...}
}

interface C {
    fun one()
    fun two()
    fun tree()
}

As you can class B extends A and also implements interface C. The problem is that in Kotlin class B which is the actual implementor of C does not have the 2 first funcs and therefore not implementing the right functions for the interface. Is there a right way to do such thing?

2
  • What exactly are you expecting? Class A's implementations of one and two satisfy the interface contract. If you want to override them, you need to mark the functions open in class A. And of course, class A itself must be marked open for your above code to compile. Commented Oct 14, 2020 at 20:59
  • @Tenfour04 I dont wanna override them, I want them to satisfy the interface but that's not the case. I'm getting Class 'B' is not abstract and does not implement abstract member public abstract fun one() Commented Oct 14, 2020 at 21:04

1 Answer 1

1
  1. The A class needs to be marked open.
  2. The super class A of the class B needs to be initialized (i.e. A())
  3. The B.tree() method requires override modifier

Apart of that, it should work...

open class A {
    fun one() {}
    fun two() {}
}

class B: A(), C {
    override fun tree() {}
}

interface C {
    fun one()
    fun two()
    fun tree()
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.