FAQ Database Discussion Community

Is there a built in Kotlin method to apply void function to value?

I wrote this method to apply a void function to a value and return the value. public inline fun <T> T.apply(f: (T) -> Unit): T { f(this) return this } This is useful in reducing something like this: return values.map { var other = it.toOther() doStuff(other) return other } To...

Are interfaces a valid substitute for utility classes in Java 8? [duplicate]

This question already has an answer here: Java 8: Interface with static methods instead of static util class 4 answers For the past decade or so, I've been using the pattern below for my Java utility classes. The class contains only static methods and fields, is declared final so...