3 ms·
The author doesn't seem to be complaining about interior mutability, AFAICT. Scala makes the case the author is complaining about clearer than Kotlin, by using
by tekacs 9y ago
The author doesn't seem to be complaining about interior mutability, AFAICT.
Scala makes the case the author is complaining about clearer than Kotlin, by using the 'def' keyword (same as functions/methods) for getters rather than 'val' (the latter can only be used for values). Matching the style of the article, it's:
class Person(val birthDay: DateTime) {
def age: Int = yearsBetween(birthDay, DateTime.now)
}
You can't use 'val' here and so excepting interior mutability, Scala 'val's don't change (and importantly, the reference you get by naming one doesn't ever change).