Dr. Florian Schmidt
09/10/2021, 6:52 PMraulraja
09/10/2021, 7:39 PMDr. Florian Schmidt
09/11/2021, 6:09 AMannotation class Companion
annotation class OverrideCompanion
interface I {
// I want this function to be implemented
// on the companion object of the
// implementing class
@Companion
fun <S, T> f(s: S): T
}
class Impl : I {
companion object {
@OverrideCompanion
fun <S, T> f(s: S): T = TODO()
}
}
raulraja
09/11/2021, 5:03 PMinterface I {
interface Companion {
fun <S, T> f(s: S): T
}
}
class Impl : I {
companion object : I.Companion {
override fun <S, T> f(s: S): T = TODO()
}
}
raulraja
09/11/2021, 5:04 PMYoussef Shoaib [MOD]
09/11/2021, 6:56 PMinterface I {
val companion: Companion
interface Companion {
fun <S: T, T> f(s: S): T
}
}
class Impl : I {
override val companion = Companion
companion object : I.Companion {
override fun <S: T, T> f(s: S): T = s
}
}
fun main(){
val i: I = Impl()
println(i.companion.f("test"))
}
Dr. Florian Schmidt
09/13/2021, 9:53 AM