Can't function references specify type parameters?
# announcements
r
Can't function references specify type parameters?
d
If I understand you correctly, no. Please clarify what exactly you mean though.
a
So like java lambdas? Where you have a method reference and you don't call the parameters because the runtime fills in the parameters for you?
lambdaCall(LambdaClass::methodReference)
like that. Cause really, this works because the runtimes fills in the correct arguments based on the method/function the method is being referenced from (right?) so ideally in kotlin, I would assume that a function reference is the same thing since kotlin uses the terms "function" and "member functions" so when I hear "function references" I think of method references in java. Which I would assume the answer to be no, but I could be wrong
r
::myfunc<A>
Say I have a function with a type like this:
Copy code
inline fun <reified A> myfunc(): String = 
   A::class.java.simpleName
how do you lift that to a method reference since the type args can't be inferred from the function arguments?
Works:
Copy code
fun myfunc2(): String = ""
val y = ::myfunc2
Does not work:
Copy code
inline fun <reified A> myfunc(): String =
        A::class.java.simpleName
val x = ::myfunc<Int>
d
You cannot. You can't inline into a method reference as far as I know. You need to use a normal lambda
r
ok, same issue when not
inline
though
d
Yes, you can't specify the type parameter like that, you need a lambda
r
👍