Hello, noob question here, under what conditions w...
# getting-started
a
Hello, noob question here, under what conditions we need to use
MyFunction.invoke()
instead of
MyFunction()
?
j
In some cases you have to use
invoke
, for instance if the function instance is nullable and you want to use the safe-call operator:
myFunction?.invoke()
. But otherwise in general I would say it's a matter of style/preference.
👍 2
👍🏼 1
a
Thanks @Joffrey
e
just the other day a case came up where
Foo()
resolves to the constructor and
Foo.invoke()
resolves to the
invoke
operator on
Foo.Companion
, https://kotlinlang.slack.com/archives/C0B8MA7FA/p1645273130231929
👍🏼 1
👍 2