更新时间:2023-12-04 16:04:29
据我所知没有.想要同一件事,我复制了ParametersAreNonnullByDefault 的> source转换为我自己的FieldsAreNonnullByDefault
和MethodsAreNonnullByDefault
,并更改了@TypeQualifierDefault
值以匹配(分别为FIELD
和METHOD
). FindBugs完美地拾取了这些新注释.
As far as I know there is none. Wanting the same thing, I copied the source for ParametersAreNonnullByDefault
into my own FieldsAreNonnullByDefault
and MethodsAreNonnullByDefault
and changed the @TypeQualifierDefault
values to match (FIELD
and METHOD
respective). FindBugs picks up these new annotations perfectly.
这是FieldsAreNonnullByDefault
的示例:
package com.sample;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import javax.annotation.meta.TypeQualifierDefault;
/**
* This annotation can be applied to a package or class to indicate that the
* classes' fields in that element are nonnull by default unless there is
* <ul>
* <li>an explicit nullness annotation
* <li>a default field annotation applied to a more tightly nested element.
* </ul>
*/
@Documented
@Nonnull
@TypeQualifierDefault(ElementType.FIELD) // <-- METHOD for return values
@Retention(RetentionPolicy.RUNTIME)
public @interface FieldsAreNonnullByDefault {
}