hey all a question regarding some code we have in ...
# getting-started
n
hey all a question regarding some code we have in our project We have an extension method defined on KFunction - "someExtensionMethod". and then we call it from a data class like this: SomeDataClass::someExtensionMethod ::SomeDataClass.someExtensionMethod now im going through kotlin doc and im still not quite sure how is this possible. or what exactly is happening? if for example that SomeDataClass has 4 params in its constructor it will invoke the extension method KFunction4.someExtensionMethod can you refer me to the place in docs that explain such behvaior?
j
Could you please post a snippet that shows this behavior? I get an error: https://pl.kotl.in/K2RGafV4J
n
Copy code
data class SomeDataClass(val param: String)
import kotlin.reflect.KFunction1
 
 fun <String, T0> KFunction1<String, T0>.someMethod(
      param:String
 ) = println("i can be called from a data class reference " + param )

::SomeDataClass.someMethod("my param")
i can be called from a data class reference my param
i executed it inside kotlin repl
j
Ah
::SomeDataClass.someMethod
is different from
SomeDataClass::someMethod
n
ops, sorry
j
I should have thought that's what you meant, no worries
In the code you posted, the constructor takes a string and spits a
SomeDataClass
so it is a valid
KFunction1<String, SomeDataClass>
And
::SomeDataClass
is a reference to the constructor, so it's ok to call the extension function on it
n
::SomeDataClass is of type Function?
👌 1
nevermind it is
👍 1
i got confused hehe
sorrrry
Copy code
(::SomeDataClass)::class
res15: kotlin.reflect.KClass<out kotlin.reflect.KFunction1<kotlin.String, Line_0.SomeDataClass>> = class Line_17$res15$1