4 ms·
you don't. Scala produces them automatically for case classes. Kotlin will treat x.count as x.getCount() if getCount exists and count doesn't. They are mostly a
by gregghz 9y ago
you don't. Scala produces them automatically for case classes. Kotlin will treat x.count as x.getCount() if getCount exists and count doesn't. They are mostly a side effect of the tools and not strictly required.
Especially in Kotlin and Scala where data tends to be immutable by default there isn't much to gain by using getters.
If your "getter" is doing more than getting the value then maybe you should not call it a getter (imo).
- saghm 9y ago> If your "getter" is doing more than getting the value then maybe you should not call it a getter (imo) I'd definitely agree there! In fact, I might go further and say that if your "getter" does more than just return a member, then by definition it isn't a getter
- lgas 9y agoI think the heart of the question was more, if the members are already public, why does Scala need to produce getters for them, why not access the members directly?
- gregghz 9y agoI honestly don't know.