Skip to content

Commit 503d198

Browse files
authored
Merge pull request #81 from rillig/roland.illig/CheckReturnValue
Add CheckReturnValue annotation
2 parents 172f606 + 1e12a4f commit 503d198

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.jetbrains.annotations;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Target;
5+
6+
/**
7+
* Specifies that the method is impure and that its return value must be used.
8+
* <p>
9+
* For pure methods (annotated with {@code @Contract(pure = true)}),
10+
* it's implied that the resulting value is important,
11+
* so this annotation would be redundant.
12+
* <p>
13+
* Some impure methods have side effects and still require the return value to be used.
14+
* For example, {@link java.io.InputStream#read(byte[])}
15+
* returns the number of bytes actually stored in the byte array.
16+
* Without checking the return value, it's impossible to say how many bytes were actually read.
17+
* <p>
18+
* This annotation should not be used if the return value of the method
19+
* provides only <i>additional</i> information.
20+
* For example, the main purpose of {@link java.util.Collection#add(Object)}
21+
* is to modify the collection, and the return value is only interesting
22+
* when adding an element to a set, to see if the set already contained that element before.
23+
* <p>
24+
* When used on a type, the annotation applies to all methods that do not return {@code void}.
25+
* <p>
26+
* When used on a package, the annotation applies to all types of that package.
27+
*
28+
* @see Contract#pure()
29+
*/
30+
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE, ElementType.PACKAGE})
31+
@ApiStatus.Experimental
32+
public @interface CheckReturnValue {
33+
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
# limitations under the License.
1515
#
1616

17-
projectVersion=23.1.0
17+
projectVersion=24.0.0
1818
#JDK_5=<path-to-older-java-version>

0 commit comments

Comments
 (0)