I can use retrolambda to enable lambdas with Android API level <24. So this works
myButton.setOnClickListener(view -> Timber.d(\"Lambdas work!\"));
Android support library(AndroidX) now has Consumer and Supplier:
androidx.appcompat:appcompat:1.0.2)androidx.appcompat:appcompat:1.1.0-alpha01)sadly only these two interfaces gets added as of writing.
Now we have Kotlin, it doesn't require you to specify the functional interface explicitly:
fun test() {
val text = withPrintStream {
it.println("Header bla bla ")
it.printf("%s, %s, %s,", "a", "b", "c").println()
}
}
// Equivalent to the following code in Java:
// Consumer action;
// action.accept(ps);
fun withPrintStream(action: (PrintStream) -> Unit): String {
val byteArrayOutputStream = ByteArrayOutputStream()
val ps = PrintStream(byteArrayOutputStream)
action(ps)
ps.flush()
return byteArrayOutputStream.toString()
}