/* * Copyright 2018-2020 The JSpecify Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.jspecify.annotations; import static java.lang.annotation.ElementType.TYPE_USE; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.Target; /** * Indicates that the annotated type * usage (commonly a parameter type or return type) is considered to include {@code null} as a * value. * *

Example usages: * *

{@code
 * @Nullable String field;
 *
 * @Nullable String getField() { return field; }
 *
 * void setField(@Nullable String value) { field = value; }
 *
 * List<@Nullable String> getList() { … }
 * }
* *

For a comprehensive introduction to JSpecify, please see jspecify.org. * *

Warning: These annotations are under development, and any aspect of their * naming, locations, or design is subject to change until the JSpecify 1.0 release. Moreover, * supporting analysis tools will be tracking the changes on varying schedules. Releasing a library * using these annotations in its API is strongly discouraged at this time. * *

Meaning per each kind of type usage

* *

The essential meaning of this annotation is always the same: the type it annotates is * considered to include {@code null} as a value. But this may affect your code a little differently * based on the kind of type usage involved. * *

* *

Where it is applicable

* *

This annotation and {@link NonNull} are applicable to any type usage except the * following cases, where they have no defined meaning: * *

* * Whether the code is {@link NullMarked} also has no consequence in the above locations. * *

Unannotated type usages

* *

For a type usage where nullness annotations are applicable but * not present, its nullness depends on whether it appears within {@linkplain NullMarked * null-marked} code; see that class for details. Note in particular that nullness information from * a superclass is never automatically "inherited". */ @Documented @Target(TYPE_USE) @Retention(RUNTIME) public @interface Nullable {}