我如何让 @ParametersAreNonnullByDefault 工作? [英] How do I get @ParametersAreNonnullByDefault to work?

查看:38
本文介绍了我如何让 @ParametersAreNonnullByDefault 工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经多次尝试让包注释 @ParametersAreNonnullByDefault 在 Maven 项目中为我工作,但没有成功.有人可以分享一个指向最小/示例 maven 项目的链接吗(或发布 pom.xml 和 package-info.java 和演示类)?

I've made several attempts at getting package annotation @ParametersAreNonnullByDefault to work for me in a maven project but with no success. Could someone share a link to a minimal/sample maven project where this is setup (or post the pom.xml and package-info.java and demo class)?

我说的是让 findbugs 处理器为我强制执行.

I'm talking about having findbugs processor enforce it for me.

推荐答案

如何申请 @ParametersAreNonnullByDefault

在您要强制执行所需行为的包中创建一个文件 package-info.java.

在该文件中,执行以下操作:

In that file, do the following:

/**
 * You should do it like this!
 */
@ParametersAreNonnullByDefault
package com.stackoverflow;

import javax.annotation.ParametersAreNonnullByDefault;

如何应用@ParametersAreNonnullByDefault

不要在 Java 源文件中执行以下操作:

How not to apply @ParametersAreNonnullByDefault

Don't do the following in a Java source file:

/**
 * But you shouldn't do it this way!
 */
@ParametersAreNonnullByDefault
package com.stackoverflow;

import javax.annotation.ParametersAreNonnullByDefault;

public class Answer { ...

像这样声明注释是不明确的.

Declaring annotations like this is ambiguous.

直接在Answer类上应用注解就可以了.

It would be OK to apply the annotation directly on Answer class.

package com.stackoverflow;

import javax.annotation.ParametersAreNonnullByDefault;

/**
 * You can do it like this also.
 */
@ParametersAreNonnullByDefault
public class Answer { ...

完全相同的事情适用于 @ParametersAreNullableByDefault 还有.

The exact same things apply to @ParametersAreNullableByDefault also.

这篇关于我如何让 @ParametersAreNonnullByDefault 工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆