@Documented @Retention(value=CLASS) @Target(value=METHOD) public @interface Contract
Method contract has the following syntax:
contract ::= (clause ';')* clause
clause ::= args '->' effect
args ::= ((arg ',')* arg )?
arg ::= value-constraint
value-constraint ::= 'any' | 'null' | '!null' | 'false' | 'true'
effect ::= value-constraint | 'fail'
The constraints denote the following:
@Contract("_, null -> null")
- method returns null if its second argument is null
@Contract("_, null -> null; _, !null -> !null")
- method returns null if its second argument is null and not-null otherwise
@Contract("true -> fail")
- a typical assertFalse method which throws an exception if true
is passed to it
Modifier and Type | Optional Element and Description |
---|---|
boolean |
pure
Specifies that the annotated method has no visible side effects, in the following sense.
|
String |
value
Contains the contract clauses describing causal relations between call arguments and the returned value
|
public abstract String value
public abstract boolean pure
Copyright © 2021. All rights reserved.