Function Types in Java
Function types and anonymous functions are novel inclusions in the Kotlin programming language that provide a streamlined syntax for communicating between components.
Their concise syntax is made possible via the -> operator, but lambdas are not supported in versions of Java prior to Java 8.
So what do these function types look like when called from Java?
The answer may seem deceptively simple: In Java, your function type is represented by an interface with a name like FunctionN, where N is the number of arguments taken as parameters.
To see this in practice, add a function type called translator to Hero.kt. translator should take a String, lowercase it, capitalize the first letter, and print out the result. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access