https://kotlinlang.org logo
#compiler
Title
# compiler
a

anlex N

03/23/2024, 3:33 PM
https://kotlinlang.org/docs/extensions.html is this function passed by value, not by reference? if passed by value, how to passed by reference?
Extension functions are normal functions with the receiver being the first parameter.
a

anlex N

03/23/2024, 4:19 PM
so it is not like C++, TypeScript. What design consideration is this syntax?
c

Chrimaeon

03/23/2024, 5:59 PM
For example, you can write new functions for a class or an interface from a third-party library that you can’t modify. Such functions can be called in the usual way, as if they were methods of the original class. This mechanism is called an extension function. There are also extension properties that let you define new properties for existing classes.
h

hfhbd

03/23/2024, 6:22 PM
Wait, I talked about Java classs code representation.
a

anlex N

03/24/2024, 3:31 AM
why not inherit from the class or use design patterns such as Decorator? why is it better than these two ways? is you says Decorator concept equal to this Decorator ?
c

Chrimaeon

03/24/2024, 6:48 AM
Because you might not have access do the class implementation. You totally misunderstand the concept of extensions.
2 Views