[英]JDK 1.7 compiler does not recognize generic class
I have a class which uses a class from Eclipse OSGI jar (org.eclipse.osgi_3.7.2.v20120110-1415.jar) and which is well compiled within Eclipse IDE and it's compiler. 我有一个使用Eclipse OSGI jar(org.eclipse.osgi_3.7.2.v20120110-1415.jar)中的类的类,该类在Eclipse IDE及其编译器中进行了很好的编译。 But if I try to compile this class with Ant and JDK 1.7 compiler, the compiler outputs these errors:
但是,如果我尝试使用Ant和JDK 1.7编译器编译此类,则编译器将输出以下错误:
[javac] /data/ant/sw_jdk1.7/test-Java7/com.tsystems.favbg.ui.core/src/com/
tsystems/favbg/ui/core/job/AbstractLoader.java:24:
error: type CopyOnWriteIdentityMap does not take parameters
[javac] private final CopyOnWriteIdentityMap<LoaderListener, String>
eventListenerMap = new CopyOnWriteIdentityMap<>();
and 和
error: cannot infer type arguments for CopyOnWriteIdentityMap;
[javac] private final CopyOnWriteIdentityMap<LoaderListener, String>
eventListenerMap = new CopyOnWriteIdentityMap<>();
[javac] reason: cannot use '<>' with non-generic class CopyOnWriteIdentityMap
Obviously javac does not recognize the class as using generics. 显然,javac无法将类识别为使用泛型。 But when I open it with Java Decompiler generic parameters are well recognized.
但是,当我使用Java Decompiler打开它时,通用参数得到了公认。 Does anybody know this problem and have a solution?
有人知道这个问题并有解决方案吗?
I would say that the problem is in the way that you are using CopyOnWriteIdentityMap
class. 我会说问题出在使用
CopyOnWriteIdentityMap
类的方式上。 I'm assuming that you are using this class: 我假设您正在使用此类:
org.eclipse.osgi.framework.eventmgr.CopyOnWriteIdentityMap
If you look at the javadocs , you will see that it is not a generic class. 如果查看javadocs ,将会看到它不是泛型类。 I also get the impression (from its package location) that it is not intended to be a general purpose utility class.
从包的位置,我还得到了一个印象,即它不是通用实用程序类。
Perhaps you are using a different version of the JAR when you are compiling in Eclipse ... one that is a generic class. 在Eclipse中进行编译时,也许正在使用其他版本的JAR ...这是一个通用类。 Either way, the compiler you are using via Ant thinks it is not generic.
无论哪种方式,您通过Ant使用的编译器都认为它不是通用的。
I am finding discrepancies when reading a certification book for SCJP based on JDK 1.6, and, trying to write (copy and paste) code, compiling within JDK 1.7. 阅读基于JDK 1.6的SCJP认证书时,我发现差异,并尝试编写(复制和粘贴)代码,并在JDK 1.7中进行编译。
Perhaps, I am making the same mistakes all over, however they seem hard to comprehend. 也许,我到处都是同样的错误,但是似乎很难理解。 For example see my posts at http://www.coderanch.com/forums/posts/list/80/467890#2679297 .
例如,请访问http://www.coderanch.com/forums/posts/list/80/467890#2679297查看我的帖子。 I am not an expert, however, I find the curriculum of Angelika Langer (http://www.angelikalanger.com/Publications.html), to be appealing for consulting, given the tutorials available on the website relating to Java Generics.
我不是专家,但是我发现Angelika Langer(http://www.angelikalanger.com/Publications.html)的课程吸引了咨询,因为网站上提供了有关Java泛型的教程。
What is your advice on the matter? 您对此事有何建议?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.