Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Fixed
-
1.7.1
-
None
-
None
-
osx, groovyConsole
Description
@Immutable annotation does not prevent changing fields:
@Immutable class Account { BigDecimal balance String customer Account deposit(amount) { balance = balance + amount this } String toString() { "Account[balance: $balance, customer: $customer]" } } def acc = new Account(0.0, "Test") acc.deposit(3.1) //should raise exception, shouldn't it? assert 3.1 == acc.balance
Maybe I got the description in http://groovy.codehaus.org/api/groovy/lang/Immutable.html wrong:
"Properties automatically have private, final backing fields with getters. Attempts to update the property will result in a ReadOnlyPropertyException." ?