Groovy 1.8.4

groovy.lang
[Java] Annotation Type Immutable

java.lang.Object
  groovy.lang.Immutable

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

deprecated:
use groovy.transform.Immutable
Authors:
Paul King


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

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