Groovy 1.7.0

groovy.lang
Annotation Type Immutable

java.lang.Object
  groovy.lang.Immutable

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@GroovyASTTransformationClass("org.codehaus.groovy.transform.ImmutableASTTransformation")
@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


Method Summary
 
Methods inherited from class Object
wait, wait, wait, hashCode, getClass, equals, toString, notify, notifyAll
 

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