Bir değişmez nesne oluşturulduktan sonra değiştirilemez — her alan bir kez ayarlanır ve durumu değiştiren hiç bir method yoktur. Bunu "değiştirmek" için yeni bir nesne oluşturursunuz.
Değişmez bir tür oluşturma
{
cents;
String currency;
{
.cents = cents;
.currency = currency;
}
Money {
(.cents + other.cents, currency);
}
{ cents; }
}
