我从eclipse得到一个警告,我知道我可以通过抑制警告将其删除,但我更愿意理解是什么原因导致它可能为空.
package-info.java
@ParametersAreNonnullByDefault
package test;
import javax.annotation.ParametersAreNonnullByDefault;
Run Code Online (Sandbox Code Playgroud)
test.java
package test;
public class Test {
public static void main( final String[ ] args ) {
System.out.println( new Test( "a" ).getS( ) );
}
private final String s;
public Test( final String s ) {
this.s = s;
}
public String getS( ) {
return this.s;//Null type safety: The expression of type String needs unchecked conversion to conform to '@Nonnull String'
}
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么我得到这个警告......
PS:
public Test( @Nonnull final String s ) …
我是 Java 新手,刚刚发现了 @Nullable 和其他此类注释,所以我尝试了它们。
我首先尝试了 Eclipse 中包含的字段,但它们不允许我将它们用于字段,这让我认为某些字段可能为空,而它们显然不能。
顺便说一句,我默认使用这个东西来使所有内容都@NonNull。
然后,我尝试了findbugs(edu.umd.cs.findbugs.annotations),但显然,整个事情都被弃用了(http://findbugs.sourceforge.net/api/edu/umd/cs/findbugs/annotations/package-摘要.html)。
我应该用什么?
我想知道是否有某种方法可以做到这一点:
type binary_operator = And | Or;;
type canonical;;
type not_canonical;;
type 'canonical boolean_expression =
| Var : int -> not_canonical boolean_expression
| Not : 'canonical boolean_expression -> 'canonical boolean_expression
| BinOp : canonical boolean_expression * binary_operator * canonical boolean_expression -> canonical boolean_expression
| BinOp : _ boolean_expression * binary_operator * _ boolean_expression -> not_canonical boolean_expression
;;
Run Code Online (Sandbox Code Playgroud)
这里的问题是我无法定义BinOp两次,而我想依赖于参数的类型......
PS:"规范"意味着"表达式中包含的n个变量由0到(n-1)的整数表示".这是一个不变的,我需要强制我的一些功能.