“Undefined reference:.. ConcurrentHashMap.keySet()"在Java 8中构建时 [英] "Undefined reference: .. ConcurrentHashMap.keySet()" when building in Java 8

查看:106
本文介绍了“Undefined reference:.. ConcurrentHashMap.keySet()"在Java 8中构建时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,我用jdk 6,7,8构建这个项目,我的目标是1.6

i have a project, and i am build this project with jdk 6,7,8 and my target is 1.6

当我构建jdk 8时我得到了这个错误:

when i build jdk 8 i get this error:

未定义的引用:java.util.concurrent.ConcurrentHashMap.KeySetView java.util.concurrent.ConcurrentHashMap.keySet()

因为我在这行中有这个代码:

since i have this code in that line:

   final Iterator<CLASS_NAME> itr = hashMap.keySet().iterator();

如何避免错误,我在互联网上进行了一些搜索,并且因为java 8改变了它的返回类型键集,我有错误。这是任何解决方案。
i我正在使用maven,而animal-sniffer-plugin会出现此错误,并出现签名错误。

how can avoid error, i made some search in internet, and since java 8 changed its return type keyset, i got error. is this any solution. i am using maven, and animal-sniffer-plugin gives this error, with signature error.

推荐答案

另一个答案建议对代码的修改(使用 keys()而不是 keySet()),以便您可以编译源代码在Java 8上运行Java 7.我认为这是一个倒退的步骤。

Another Answer suggests a modification to your code (using keys() instead of keySet()) so that you can compile your source code on Java 8 and run on Java 7. I think that is a retrograde step.

相反:


  • 如果您的目标是创建一个产品在Java 6,7和8上运行的软件的构建,那么你最好的选择是在JDK 6上进行生产。

  • If your aim is to create a production build of your software that will run on Java 6, 7 and 8, then your best bet is to do your production builds on JDK 6.

如果您的目标是在Java 8上进行开发构建(但目前在源代码级别保持向后兼容),则更改动物嗅探器的maven插件配置以忽略这些类;请参阅 http://mojo.codehaus.org/animal-sniffer-maven-plugin /examples/checking-signatures.html 以获得解释。

If your aim is to do your development builds on Java 8 (but stay backwards compatible at the source code level for now), then change the maven plugin configs for animal-sniffer to ignore these classes; see http://mojo.codehaus.org/animal-sniffer-maven-plugin/examples/checking-signatures.html for an explanation.

然而,动物嗅探器可能会忽略太多;例如它不会告诉您是否在 ConcurrentHashMap 中使用 new Java 8方法。你需要考虑到这种可能性......

However, there is a risk that animal-sniffer will ignore too much; e.g. it won't tell you if you use new Java 8 methods in ConcurrentHashMap. You will need to allow for that possibility ....

如果你的目标是转向Java 8(这样你就可以开始使用新的Java 8功能了)在你的代码中),然后就这样做。您的代码不会向后兼容,但您永远不能支持旧版本的Java ...

If your aim is to move to Java 8 (so that you can start using new Java 8 features in your code), then just do it. Your code won't be backward compatible, but you can't support old versions of Java for ever ...

(如果考虑全局,这些建议并不相互排斥。)

(These suggestions are not mutually exclusive, if you consider the big picture.)

这篇关于“Undefined reference:.. ConcurrentHashMap.keySet()&quot;在Java 8中构建时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆