The role of Spring@Nullable annotation (source code + concise and detailed analysis)

Let me emphasize first that whether to follow this annotation is entirely up to you (there is no parameter verification function)

Click into the annotation source code to see that the @Nullable annotation inherits multiple annotation interfaces . The following analyzes the inherited interfaces in turn:

@Tatget

This annotation indicates what the target of this annotation can be

ElementType.METHOD(Method)

ElementType.PARAMETER(method parameter)

ElementType.FIELD (field, enumeration constant)

@Retention

Represents the life cycle of annotations

RetentionPolicy.RUNTIME (the annotation is not only saved in the class file, but still exists after jvm loads the class file)

@Documented

Generated docs are annotated (showing @Nullable)

@NonNull

@NonNull modifies fields, methods, and parameters, so fields cannot be null, method return values ​​cannot be null, and parameters cannot be null.

As for the function of when = When.MAYBE, I speculate that it is only the function of marking (the following is the source code of the annotation @NonNull)

@TypeQualifierNickname

When other annotations use this annotation (@Nullable)

All annotations used by @Nullable ( except @TypeQualifierNickname) will be added

at last,

        Hope the article is helpful to you. . .

Guess you like

Origin blog.csdn.net/m0_63930592/article/details/129820555