3 ms·
You have to manually define its constructor, manually provide getters if you want the value to be immutable, put each class in a separate file (or namespaced in
by SamReidHughes 11y ago
You have to manually define its constructor, manually provide getters if you want the value to be immutable, put each class in a separate file (or namespaced inside another class), and if your type has finitely many alternatives you have to set up the whole visitor pattern thing. Compare that with C#'s properties and readonly, Scala's case classes, Swift's enum types.
- bcg1 11y agoMaking immutable structures in Java truly does suck... this is the most valid complaint that I've heard in a long time about the language. It would be extremely easy to implement properties as syntactic sugar in the language or via built-in annotations without changing the class file spec at all.