I have a java method written as such ```static Fu...
# getting-started
c
I have a java method written as such
Copy code
static Function1<MyManager, String> doTheManaging(){
    return MyManager::condense;
}
The kotlin converter can't seem to convert this. Can anyone point me in the right direction? Converter gives me a new companion object then
Copy code
fun doTheManaging(): Function1<MyManager, String> {
 return { valueMap: Map<String, Any> -> condense(valueMap)}
}
but the entire return statement is red
n
try putting
Function1<MyManager, String>
right after the
return
also...Map<String, Any> != MyManager.
also if Function1 here is Kotlin's own Function1, you can just say
(MyManager) -> String
instead.
c
@nanodeath so if I'm understanding correctly, would you say that this is the correct conversion?
Copy code
fun doTheManaging(): Function1<MyManager, String> {
 return { valueMap: MyManager -> valueMap.condense()}
}
n
assuming
condense()
returns a String...should work. what is Function1 exactly?
c
Sorry for asking this seemingly trivial question. Just the whole function stuff is a bit confusing to me. I always use the converter and never had these types of issues before.
condense does return a string!
n
the best thing might be actually
Copy code
fun doTheManaging(valueMap: MyManager): String = valueMap.condense()
and then use a method reference
but if a method reference isn't possible,
Copy code
fun doTheManaging(): (MyManager) -> String =
    { valueMap: MyManager -> valueMap.condense }
should also do it, but...it admittedly a little weirder.
c
Okay. Thanks so much for your help. I think this is starting to make sense now.
n
👍 the converter is usually pretty good, but...yeah, seems like it failed hard this time.