Hello, I've spent so much time without managing to...
# getting-started
g
Hello, I've spent so much time without managing to get any response: Given a
Kfunction
obtained from an expression such as
obj::method
where obj is an instance from a Class. How can I retrieve the underlying
obj
from the
Kfunction
???
s
class Foo{ fun foo()=println("foo") } val obj:Foo = Foo() val action:()->Unit = obj::foo action.invoke() action() output :- foo foo "If you could elaborate more on which object you want to retrieve and from what"??
Tyep of action KFunction0<Unit>
g
yes, my question is: how do I retrieve obj from action?
If I know only
action
, is there a way to access
obj
?
Internally, obj is stored inside action - it's necessary to invoke it, but I can not find a way to access it
k
KFunction doesn't need to be defined on an object. What happens in that case with your requirements?
g
@Bhullnatik it's counter intuitive, but instanceParameter is null when you provide an instance (obf::foo) - not null if you use the syntax Foo::foo 🤷‍♂️
@Kirill Grouchnikov I understand it can be null, but I'd like to be able to retrieve it when not null
s
Not sure if this is possible but if someone knows how please explain us in briefly. I tried but still can't figure it out.