我怎么@ParametersAreNonnullByDefault工作? [英] How do I get @ParametersAreNonnullByDefault to work?
问题描述
我在得到包注释@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.
推荐答案
创建你的包,你要执行所需的行为的文件 package-info.java
。
How to apply @ParametersAreNonnullByDefault
Create a file package-info.java
in your package where you want to enforce the desired behavior.
在该文件中,执行以下操作:
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.
这将是确定,直接套用诠释答
类。
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 { ...
完全相同的东西应用到<一个href=\"http://jsr-305.google$c$c.com/svn/trunk/javadoc/javax/annotation/ParametersAreNullableByDefault.html\"><$c$c>@ParametersAreNullableByDefault$c$c>也。
这篇关于我怎么@ParametersAreNonnullByDefault工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!