3 ms·
Immutable classes are far easier to reason about than mutable classes. You run the constructor and know "this instance won't ever change again" - but it means i
by sgift 9y ago
Immutable classes are far easier to reason about than mutable classes. You run the constructor and know "this instance won't ever change again" - but it means if you want a change you need to create a copy with the changed data, which can be a performance problem if you have to do it very often.
See the difference between GregorianCalendar (or Date) and the more current java date APIs. The new ones are immutable and every "mutable" operation returns a new object instead of changing the old one.