groovy.lang
Annotation Type Immutable


Deprecated. use groovy.transform.Immutable

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

Note: This class is Deprecated, please use groovy.transform.Immutable.

Class annotation used to assist in the creation of immutable classes.

It allows you to write classes in this shortened form:

 @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
 
The @Immutable annotation instructs the compiler to execute an AST transformation which adds the necessary getters, constructors, equals, hashCode and other helper methods that are typically written when creating immutable classes with the defined properties.

A class created in this way has the following characteristics:

Immutable 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-2012 The Codehaus. All rights reserved.