Danish Ansari
09/24/2021, 7:27 AMString
(just a scenario), so does that have any impact on performance?
Just want to understand how exactly extension functions work and if there's any cost (or disadvantage) in using it that I should be aware of.Joffrey
09/24/2021, 7:29 AMRoukanken
09/24/2021, 7:31 AMStringUtils
class with 1000 static methods, each of which takes a string as first parameters will be similarDanish Ansari
09/24/2021, 7:32 AMDanish Ansari
09/24/2021, 7:33 AMJoffrey
09/24/2021, 7:39 AMJoffrey
09/24/2021, 7:44 AMRoukanken
09/24/2021, 7:45 AMopen class A {
open fun doSmthElse() = println("A.doSmthElse")
}
class B : A() {
override fun doSmthElse() = println("B.doSmthElse")
}
fun A.doSmth() = println("A.doSmth")
fun B.doSmth() = println("B.doSmth")
fun main() {
val x: A = B() // this line is at fault: x's type is A, but it stores instance of type B
x.doSmth()
x.doSmthElse()
}
this will print
A.doSmth
B.doSmthElse
But that's not really fault of extension funcs, but the difference between methods and top-level functionsDanish Ansari
09/24/2021, 7:50 AM