Dennis Schröder
04/12/2019, 9:41 AMdata class Foo(val one: String, val two: String) {
fun bar() = println(one + two)
}
fun Foo.bar() = println(one + two)
Can anybody explain me the difference? Is it just another way of writing the same functionality?
Are there rules when it is better to use member functions and when extension functions? I thought of extension functions of mostly useful to extend third party code.diesieben07
04/12/2019, 9:43 AMoverride
an extension function or make it abstract. They are just syntactic sugar for top-level functions where the first parameter is denoted as a receiver.ribesg
04/12/2019, 9:43 AMFoo.class
, the second one as a static method of TheFileKt.class
taking a Foo
as parameterhho
04/12/2019, 9:44 AMhho
04/12/2019, 9:44 AMDennis Schröder
04/12/2019, 9:49 AMDias
04/12/2019, 10:37 AMDias
04/12/2019, 10:38 AMmax
04/12/2019, 2:31 PM