001/* 002 * Copyright 2002-2019 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.lang; 018 019import java.lang.annotation.Documented; 020import java.lang.annotation.ElementType; 021import java.lang.annotation.Retention; 022import java.lang.annotation.RetentionPolicy; 023import java.lang.annotation.Target; 024 025import javax.annotation.Nonnull; 026import javax.annotation.meta.TypeQualifierNickname; 027import javax.annotation.meta.When; 028 029/** 030 * A common Spring annotation to declare that annotated elements can be {@code null} under 031 * some circumstance. 032 * 033 * <p>Leverages JSR-305 meta-annotations to indicate nullability in Java to common 034 * tools with JSR-305 support and used by Kotlin to infer nullability of Spring API. 035 * 036 * <p>Should be used at parameter, return value, and field level. Methods override should 037 * repeat parent {@code @Nullable} annotations unless they behave differently. 038 * 039 * <p>Can be used in association with {@code @NonNullApi} or {@code @NonNullFields} to 040 * override the default non-nullable semantic to nullable. 041 * 042 * @author Sebastien Deleuze 043 * @author Juergen Hoeller 044 * @since 5.0 045 * @see NonNullApi 046 * @see NonNullFields 047 * @see NonNull 048 */ 049@Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD}) 050@Retention(RetentionPolicy.RUNTIME) 051@Documented 052@Nonnull(when = When.MAYBE) 053@TypeQualifierNickname 054public @interface Nullable { 055}