All Downloads are FREE. Search and download functionalities are using the official Maven repository.

javolution.lang.Immutable Maven / Gradle / Ivy

The newest version!
/*
 * Javolution - Java(TM) Solution for Real-Time and Embedded Systems
 * Copyright (C) 2012 - Javolution (http://javolution.org/)
 * All rights reserved.
 * 
 * Permission to use, copy, modify, and distribute this software is
 * freely granted, provided that this notice is preserved.
 */
package javolution.lang;

/**
 * 

An object capable of returning a {@link #value value} not subject or * susceptible of change or variation. For example, {@code Immutable>} * has a {@code 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 * {@link ValueType} sub-interface can be implemented. * [code] * class Polygon extends Shape implements ValueType { // extends Immutable * private List vertices; * public Polygon(Immutable> vertices) { // Immutable 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. * }[/code]

*

{@link javolution.util.FastCollection FastCollection/FastMap} have * direct support for immutable. * [code] * Polygon triangle = new Polygon(new FastTable().addAll(p1, p2, p3).toImmutable());[/code]

* * @author Jean-Marie Dautelle * @version 6.0, July 21, 2013 * @param The type of the immutable constant value. * @see * Wikipedia: Immutable Object * @see javolution.util.FastCollection#toImmutable */ public interface Immutable { /** * Returns the constant value held by this object. */ T value(); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy