https://kotlinlang.org logo
#announcements
Title
# announcements
r

raulraja

09/26/2017, 6:08 PM
Can't function references specify type parameters?
d

diesieben07

09/26/2017, 6:52 PM
If I understand you correctly, no. Please clarify what exactly you mean though.
a

alexcouch

09/26/2017, 6:56 PM
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

raulraja

09/26/2017, 7:10 PM
::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

diesieben07

09/26/2017, 7:42 PM
You cannot. You can't inline into a method reference as far as I know. You need to use a normal lambda
r

raulraja

09/26/2017, 7:49 PM
ok, same issue when not
inline
though
d

diesieben07

09/26/2017, 7:49 PM
Yes, you can't specify the type parameter like that, you need a lambda
r

raulraja

09/26/2017, 7:50 PM
👍
2 Views