Marc Fearby
02/03/2023, 2:17 AMKFunction<String>
variable, is there a way to invoke it on a class? I have an interface with two functions, both of which return a string, and I’d like to choose between one or the other, and pass it to another function to invoke on objects which implement that interface (using the reference to the function name). Is this possible? Thank you.Marc Fearby
02/03/2023, 2:22 AMKFunction<String>
reference like this:
val summaryFunction = if (someType == "Something") MyInterface::toSummary else MyInterface::toOtherSummary
And I want to be able to invoke that function reference instead of the hard-coded toSummary() in the example below:
if (someObject == null) otherObject.toSummary()
else """
The original details are:
${someObject.toSummary()}
and the new details are:
${otherObject.toSummary()}
""".trimIndent()
Vampire
02/03/2023, 2:47 AMKFunction<String>
, but a KFunction1<MyInterface, String>
and you call it with .call(theInstanceHere)
Marc Fearby
02/03/2023, 3:05 AMVampire
02/03/2023, 3:05 AMMarc Fearby
02/03/2023, 3:06 AMVampire
02/03/2023, 3:06 AM