argutia.tools.annotations
Annotation Type Immutable
@Documented
@Target(value=TYPE)
@Retention(value=RUNTIME)
public @interface Immutable
The class to which this annotation is applied is immutable. This means that its state cannot be
seen to change by callers, which implies that:
- all public fields are final,
- all public final reference fields refer to other immutable objects, and
- constructors and methods do not publish references to any internal state which is
potentially mutable by the implementation.
Immutable objects may still have internal mutable state for purposes of performance optimization;
some state variables may be lazily computed, so long as they are computed from immutable state
and that callers cannot tell the difference.
- Author:
- Java Concurrency in Practice
- See Also:
- Java theory and practice: To mutate or not to mutate?
- Notes:
- Copyright (c) 2005 Brian Goetz and Tim Peierls Released under the Creative Commons Attribution
License
Official home: http://www.jcip.net
- Informations:
- Benefits of immutability:
Immutable classes, when used properly, can greatly
simplify programming. They can only be in one state, so as long as they are properly constructed,
they can never get into an inconsistent state. You can freely share and cache references to
immutable objects without having to copy or clone them; you can cache their fields or the results
of their methods without worrying about the values becoming stale or inconsistent with the rest
of the object's state. Immutable classes generally make the best map keys. And they are
inherently thread-safe, so you don't have to synchronize access to them across threads.
Argutia JavaDoc
23 décembre 2007