groovy.lang
Annotation Type Immutable


@Retention(value=RUNTIME)
@Target(value=TYPE)
public @interface Immutable

Class annotation used for making a class immutable.

It allows you to write code snippets like this:

 @Immutable class Customer {
     String first, last
     int age
     Date since
     Collection favItems
 }
 def d = new Date()
 def c1 = new Customer(first:'Tom', last:'Jones', age:21, since:d, favItems:['Books', 'Games'])
 def c2 = new Customer('Tom', 'Jones', 21, d, ['Books', 'Games'])
 assert c1 == c2
 
A class created in this way has the following characteristics:

Such classes are particularly useful for functional and concurrent styles of programming and for use as key values within maps.

Limitations:

Author:
Paul King


Copyright © 2003-2010 The Codehaus. All rights reserved.