Obiekt niezmienny nie może być zmieniony po jego skonstruowaniu — każde pole jest ustawiane raz, i nie ma żadnych metod modyfikujących stan. Aby go "zmienić", tworzysz nowy obiekt.
Budowanie typu niezmiennego
java
{
cents;
String currency;
{
.cents = cents;
.currency = currency;
}
Money {
(.cents + other.cents, currency);
}
{ cents; }
}
