|
| 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 | +} |
0 commit comments