Karlo Lozovina
02/18/2022, 5:33 PMval
property doesn't always return the same value? Say it has a getter, and does some computation on other mutable parts of the class. Is it horrible? Amazingly bad?Paul Griffith
02/18/2022, 5:40 PMKarlo Lozovina
02/18/2022, 5:52 PMKlitos Kyriacou
02/18/2022, 6:31 PMval
properties even in the Kotlin API itself, such as List.size
.mkrussel
02/18/2022, 6:41 PMList.size
. If it is something that is calculated randomly or has side effects, then being a val
would be bad.ephemient
02/20/2022, 3:20 PMPrefer a property over a function when the underlying algorithm:
• does not throw
• is cheap to calculate (or cached on the first run)
• returns the same result over invocations if the object state hasn't changedso if it returns a different value without state changes, it's recommended not to use a
val