|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | ||||||||
@Documented @Target(value=TYPE) 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
Immutable objects are inherently thread-safe; they may be passed between threads or published without synchronization.
This annotation is trusted, i.e., it is not verified by analysis.
Presently its use is for documentation and to quiet warnings similar to
ThreadSafe. It is intended that this annotation will be verified in
the future.
Implementation note: This annotation is derived from
@Immutable proposed by Brian Goetz and Tim Peierls in the
book Java Concurrency in Practice (Addison-Wesley 2006) we have simply
adapted it to have semantics as a promise. Further, the annotation in net.jcip.annotations may be used instead of this one with the same tool
behavior. One difference between the two annotations is that the one in
net.jcip.annotations has retention policy of
RetentionPolicy.RUNTIME while the one in com.surelogic defaults to RetentionPolicy.CLASS.
Point class below is considered thread-safe.
@Immutable
public class Point {
final int f_x;
final int f_y;
public Point(int x, int y) {
f_x = x;
f_y = y;
}
public int getX() {
return f_x;
}
public int getY() {
return f_y;
}
}
@annotate tag.
/**
* @annotate Immutable
*/
public class Point {
...
}
ThreadSafe
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | ||||||||