|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | ||||||||
@Documented
@Target(value={FIELD,CONSTRUCTOR,METHOD,PARAMETER})
public @interface ReadOnlyDeclares that the parameter, receiver, return value, or field to which this annotation is applied cannot be used to mutate an object. A readonly variable differs from a variable to an immutable object in that readonly does not exclude the existence of references used for mutation. A readonly parameter, unlike a borrowed parameter for which mutation is not permitted, may be compromised/aliased. Thus we normally do not recommend variables be annotated readonly unless the callee wishes to retain a reference.
A Borrowed field may be annotated readonly to indicate that the
field cannot be used for mutation.
It is a modeling error to annotate a variable of
primitive type (e.g., @ReadOnly("return") public int getValue()
would generate a modeling error). It is a modeling error to annotate a
parameter if the parameter's type is primitive (e.g.,
public void setValue(@Unique int value) would generate a
modeling error).
This annotation is not currently checked by analysis and is still experimental. It may be used for documentation purposes.
Return Value:
Field:
@annotate tag. One complication is that the parameter being
annotated must be explicitly specified because the annotation can no longer
appear in the context of the parameter declaration.
/**
* @annotate ReadOnly("a, b, c")
*/
public void m1(Object a, Object b, Object c) { ... }
This annotation states that the three parameters are readonly. Alternatively,
you can use several annotations as shown below.
/**
* @annotate ReadOnly("a")
* @annotate ReadOnly("b")
* @annotate ReadOnly("c")
*/
public void m1(Object a, Object b, Object c) { ... }
Borrowed,
Immutable| Optional Element Summary | |
|---|---|
String |
value
When annotating a method, this attribute is used to disambiguate whether the annotation refers to the method's receiver, the method's return value, or both. |
public abstract String value
""
"this"
"return"
"this, return"
"return, this"
The values are interpreted thusly
"this", it indicates the
receiver is readonly. This value is only allowed on methods.
"return", it indicates the
return value is readonly. This value is allowed on methods and constructors.
"this" and "return", it
indicates that both the receiver and the return value are readonly. This
value is only allowed on methods.
This attribute is not used when annotating a parameter or a field: the attribute value must be the empty string in these cases.
The value of this attribute must conform to the following grammar (in Augmented Backus–Naur Form):
value = [("this" ["," "return"]) / ("return" ["," "this"])] ; See above comments
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | ||||||||