T
- The type of the immutable constant value.public interface Immutable<T>
An object capable of returning a value
not subject or
susceptible of change or variation. For example, Immutable<List>>
has a List
value which is guaranteed to be constant (not modifiable
by anybody). Classes implementing this interface do not need themselves to
be unmodifiable. If the value and the class are the same, the
ValueType
sub-interface can be implemented.
class Polygon extends Shape implements ValueType<Shape> { // extends Immutable<Shape> private List<Point2D> vertices; public Polygon(Immutable<List<Point2D>> vertices) { // Immutable<List> has a constant List value. this.vertices = vertices.value(); // No defensive copying required (vertices.value() is certified constant). } public Polygon value() { return this; } // As per ValueType contract. }
FastCollection/FastMap
have
direct support for immutable.
Polygon triangle = new Polygon(new FastTable<Point2D>().addAll(p1, p2, p3).toImmutable());
FastCollection.toImmutable()
T value()
Copyright © 2005-2013 Javolution. All Rights Reserved.