https://kotlinlang.org logo
#getting-started
Title
# getting-started
z

zokipirlo

04/05/2022, 10:36 AM
Is it possible to somehow call function in different interfaces to combine all results? How to implement
toMetadata
to call all
buildMetadata
function and merge lists?
Copy code
interface Meta {
    fun buildMetadata(): List<String>
}

interface FeatA : Meta {
   override fun buildMetadata(): List<String> = listOf("A")
}

interface FeatB : Meta {
   override fun buildMetadata(): List<String> = listOf("B")
}

class ObjC: FeatA, FeatB {
    override fun buildMetadata(): List<String> = emptyList()
    fun toMetadata(): List<String> // //What to do here to combine all lists (metadata) from interfaces?
}

fun main() {
    val c = ObjC()
    println(c.toMetadata()) // expecting ["A", "B"]
}
e

ephemient

04/05/2022, 11:03 AM
https://kotlinlang.org/docs/inheritance.html#overriding-rules
Copy code
super<FeatA>.buildMetadata() + super<FeatB>.buildMetadata()
❤️ 1
2 Views