Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Critical
-
Resolution: Fixed
-
Affects Version/s: 1.7.1
-
Fix Version/s: 1.7.2, 1.8-beta-1
-
Component/s: None
-
Labels:None
-
Environment:osx, groovyConsole
-
Testcase included:yes
-
Number of attachments :
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." ?