is it possible to do something like swizzling in k...
# announcements
a
is it possible to do something like swizzling in kotlin?
k
s
i guessed Pointer Swizzling for serialisation https://en.wikipedia.org/wiki/Pointer_swizzling
maybe you could tell us what you want to achieve and people could suggest the kotlin way of doing it?!
a
sorry, I was talking about method swizzling of swift https://nshipster.com/method-swizzling/ or monkey patching
Monkey patching is reopening the existing classes or methods in class at runtime and changing the behavior, which should be used cautiously, or you should use it only when you really need to. As Python is a dynamic programming language, Classes are mutable so you can reopen them and modify or even replace them.
k
Then it's possible in Kotlin/JVM with the same code.
a
thanks 😄
n
generally, from what I’ve seen, you are better using an extension method rather than doing this
m
Why use a safe language just to go out of your way trying to break the safety mechanisms? 😛
d
Generally, runtime redefinition of methods is not as widely used on the JVM. There might be alternative ways of approaching the problem we could suggest based on what you are trying to do.
n
Basically yea. Also I imagine it’ll hit you hard like doing reflection on the JVM. also I imagine there is a much better way to achieve what you want to do in a more “JVM friendly” way 🤔
625 Views