偏食外空注释为java.lang.Object继承#的getClass() [英] Eclipse external null annotation for java.lang.Object#getClass()
问题描述
我使用Eclipse中提供火星外空注释设施。我想添加一个外部注释为的java.lang.Object#的getClass()
,但似乎无法得到签名的权利。我试过以下变化:
I'm using the external null annotation facility available in Eclipse Mars. I'm trying to add an external annotation for java.lang.Object#getClass()
but can't seem to get the signature right. I've tried the following variations:
@NonNull Class<?> getClass() [()L1java/lang/Class<*>;]
@NonNull Class<@NonNull ?> getClass() [()L1java/lang/Class<*1>;]
但继续获得通过调用的getClass()
来接受类和LT的实例的方法的结果时警告;?&GT;
,其中的参数被注解为 @NonNull
。
but continue to get a warning when passing the result of invoking getClass()
to a method that accepts an instance of Class<?>
, where that parameter is annotated with @NonNull
.
以下是重现该问题最小的Eclipse项目的火星相关的文件(本例中使用的第一个空注释的变化之上,但使用第二个变化时,我也得到了同样的警告):
Below are the relevant files from a minimal Eclipse Mars project that reproduces the issue (this example uses the first null annotation variation above, but I also get the same warning when using the second variation):
的火星的Eclipse版本(4.5.0; 20150621-1200)用于Windows 64位的结果
的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;
注释/ JAVA / LANG / Object.eea
class java/lang/Object
getClass
()Ljava/lang/Class<*>;
()L1java/lang/Class<*>;
.settings / org.eclipse.jdt.core。preFS (部分)
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
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="annotationpath" value="/null-annotation-test/annotations"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="org.eclipse.jdt.annotation_2.0.100.v20150311-1658.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
有关上述项目,我收到的第10行以下警告的 Foo.java 的(其中平面广告类型
叫):
For the above project, I receive the following warning on line 10 of Foo.java (where printType
is called):
Null type safety (type annotations): The expression of type 'Class<capture#of ? extends Foo>' needs unchecked conversion to conform to '@NonNull Class<?>'
这是同样的警告,我得到不对外空注解是present。
which is the same warning I get without the external null annotation being present.
我如何正确地创建了的java.lang.Object#的getClass外空注释()
删除此警告?或者是我在平面广告类型
?
How do I correctly create an external null annotation for java.lang.Object#getClass()
to remove this warning? Or is my problem in the declaration of printType
?
推荐答案
路易·瑟曼是正确的,在类型检查方面不存在的有一个的的getClass()
方法,但每个类都有它自己专门的签名方法。因此,在一个.eea文件没有签名都不会匹配实际的getClass()方法。
Louis Wasserman is correct, in terms of type checking there is not one getClass()
method, but each class has it's own method with specialized signature. Hence no signature in a .eea file will ever match the actual getClass() methods.
我提交了 RFE 投入约<$更多的专业知识C $ C>的getClass()入编译器,这样,所需的此兽没有外部的注释。
I filed an RFE to put more special knowledge about getClass()
into the compiler, so that no external annotations are needed for this beast.
编辑::此功能已经实现,并会与Eclipse 4.6(霓虹灯)公布
This feature has been implemented and will be released with Eclipse 4.6 (Neon).
这篇关于偏食外空注释为java.lang.Object继承#的getClass()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!