[英]Null annotation processor in Eclipse
I'm using the Eclipse JDT Null annotation processor and I'm getting some weird behaviour when using java.lang.Class. 我正在使用Eclipse JDT Null注释处理器,并且在使用java.lang.Class时我遇到了一些奇怪的行为。
package test;
import org.eclipse.jdt.annotation.Nullable;
public class AnnotationSpul {
@Nullable
public <V> V get1(Class<V> type) {
return get2(type); //This line has a warning
}
@Nullable
public <V> V get2(Class<V> type) {
return null;
}
}
This is my package info: 这是我的包裹信息:
@NonNullByDefault({ PARAMETER, RETURN_TYPE, FIELD })
package test;
import static org.eclipse.jdt.annotation.DefaultLocation.FIELD;
import static org.eclipse.jdt.annotation.DefaultLocation.PARAMETER;
import static org.eclipse.jdt.annotation.DefaultLocation.RETURN_TYPE;
import org.eclipse.jdt.annotation.NonNullByDefault;
The warning I get is: "The expression of type '@NonNull Class' needs unchecked conversion to conform to '@NonNull Class<@Nullable V>'" 我得到的警告是:“'@NonNull Class'类型的表达式需要未经检查的转换以符合'@NonNull Class <@Nullable V>'”
I don't understand why I get the warning. 我不明白为什么我会收到警告。 The method signatures are exactly the same, so why does the value passed need conversion?
方法签名完全相同,那么为什么传递的值需要转换? Why is
type
inferred as @NonNull Class<V>
in one method and @NonNull Class<@Nullable V>
in the other? 为什么在一个方法
@NonNull Class<@Nullable V>
type
推断为@NonNull Class<V>
在另一个方法中@NonNull Class<@Nullable V>
?
This was a bug in ecj 4.4 . 这是ecj 4.4中的一个错误 。 In a combination of type inference and null inference ecj over-eagerly inferred the type parameter to
@Nullable V
. 在类型推断和空推理的组合中,ecj过度地将类型参数推断为
@Nullable V
The bug was fixed in 4.5M5 , so the upcoming release 4.5 (Mars) will accept the program as expected. 该错误已在4.5M5中修复 ,因此即将发布的版本4.5(Mars)将按预期接受该程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.