xii
07/07/2020, 4:24 PMandylamax
07/07/2020, 4:59 PMBetterTest.Companion
) does not extend from Test.Companion
. In fact, there isn't even a function called BetterTest.foo(test: Test)
So, in your specific situation. Just go ahead and write the function on BetterTest Companion Object.xii
07/07/2020, 5:01 PMandylamax
07/07/2020, 5:08 PMxii
07/07/2020, 5:08 PMandylamax
07/07/2020, 5:12 PMclass Test(val a: String) {
companion object {
fun foo(t: Test){
// do foo things
}
}
}
class BetterTest(override val a: String) : Test(a) {
companion object {
fun foo(t: Test) {
// do foo-lish things
}
}
}
// To call foo from Test, you just type
Test.foo(Test("a")) // No need to type Test.Companion.foo(Test("a"))
// To call foo from BetterTest you just type
BetterTest.foo(Test("a"))
BetterTest.foo(BetterTest("b")) // since BetterTest extends Test
xii
07/08/2020, 7:42 AM