I'm studying about operator overloading in kotlin and I ran into invoke
method. When I did my research about it I found out it works much similar to init
constructor of every class.
I cannot get my head around the difference and they seem to be alike because everything we do in invoke
method, it can be done in init
constructor as well.
so what is the difference and when should we use each?
invoke
is a method (which happens to be also an operator), andinit
is an initializing block - they have nothing in common. I assume your problem is the lack of investing into reading the docs and trying out the code – Catnap