java.lang.Object的Eclipse外部null注释#getClass()

我正在使用Eclipse Mars中提供的外部null注释工具。 我正在尝试为java.lang.Object#getClass()添加外部注释,但似乎无法使签名正确。 我尝试了以下变化:

 @NonNull Class getClass() [()L1java/lang/Class;] @NonNull Class getClass() [()L1java/lang/Class;] 

但是在将调用getClass()的结果传递给接受Class实例的方法时会继续收到警告,其中该参数使用@NonNull注释。

下面是重现问题的最小Eclipse Mars项目的相关文件(此示例使用上面的第一个null注释变体,但在使用第二个变体时我也得到相同的警告):

适用于Windows 64位的Eclipse Mars Release(4.5.0; 20150621-1200)
Oracle JDK 1.8.0_60

SRC /酒吧/ Foo.java

 package bar; public class Foo { private static void printType(Class type) { System.out.println(type.getName()); } public static void main(String[] args) { Foo foo = new Foo(); printType(foo.getClass()); } } 

SRC /酒吧/ package-info.java

 @org.eclipse.jdt.annotation.NonNullByDefault package bar; 

注解/爪哇/郎/ Object.eea

 class java/lang/Object getClass ()Ljava/lang/Class; ()L1java/lang/Class; 

.settings / org.eclipse.jdt.core.prefs (partial)

 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=warning org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled ... org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 ... org.eclipse.jdt.core.compiler.compliance=1.8 ... org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=enabled ... org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error org.eclipse.jdt.core.compiler.problem.nullReference=error org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning ... org.eclipse.jdt.core.compiler.problem.potentialNullReference=error ... org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning ... org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=enabled ... org.eclipse.jdt.core.compiler.source=1.8 

的.classpath

            

对于上面的项目,我在Foo.java的第10行收到以下警告(其中printType ):

 Null type safety (type annotations): The expression of type 'Class' needs unchecked conversion to conform to '@NonNull Class' 

这是我没有外部空注释存在的相同警告。

如何为java.lang.Object#getClass()正确创建外部null注释以删除此警告? 或者是printType声明中的printType

Louis Wasserman是正确的,在类型检查方面没有一个 getClass()方法,但每个类都有自己的方法和专门的签名。 因此,.eea文件中的签名将不会与实际的getClass()方法匹配。

我提交了一份RFE ,将更多关于getClass()特殊知识放入编译器中,因此这个野兽不需要外部注释。

编辑:此function已经实现,将与Eclipse 4.6(Neon)一起发布。