What is the best way to access a dynamic value like an array size inside a class? In Java, I would create a getSize() function that would return the size of the array. In Kotlin, there are two ways of doing this:
// One solution
val size get() = myArray.size
// Another solution
fun size() = myArray.size
According to the Kotlin Coding Conventions one should prefer a function to a property if the size of ‘myArray’ could vary between calls and therefore violate the fourth condition.
@alanfo I don’t think it should be interpreted so strict that the property couldn’t vary between calls at all. For a class with mutable state it should return the same result if its state is unchanged.