I’ve been converting Java to Kotlin recently, and ...
# getting-started
m
I’ve been converting Java to Kotlin recently, and there’s something I don’t quite get. Sometimes Kotlin uses properties for functions with
val cmpValue: Int get() { when (mod) -> return 0 ... }
when it was previous a function. On close inspection, it appears that it’s doing this for immutable functions that don’t change state (let me know if I’m wrong here). Why is a property with
val
and
get()
with no
set()
preferred over a function with
fun
? It’s ever-so-slightly more verbose, and I really don’t think of these as properties, regardless of its immutability.