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?
A
class needs to be marked open
. A
of the class B
needs to be initialized (ie A()
) 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()
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.