简体   繁体   English

是否可以将ConcurrentHashmap计算与java 7源代码级别一起使用?

[英]Is it possible to use ConcurrentHashmap compute with java 7 source level?

We have an old project using gwt 2.6 and therefore we need to compile with -source 1.7 option. 我们有一个使用gwt 2.6的旧项目,因此我们需要使用-source 1.7选项进行编译。

The JRE and JDK used are 1.8, but compile with 1.7 source code option. 使用的JRE和JDK是1.8,但使用1.7源代码选项进行编译。

We want to use the new compute function from ConcurrentHashMap which is only available from java 8. When using eclipse and maven everything compiled well. 我们想要使用ConcurrentHashMap中的新计算函数 ,它只能从java 8中获得。当使用eclipse和maven时,一切编译得很好。 On the other hand IntelliJ is complaining. 另一方面,IntelliJ正在抱怨。 My question is, will it work or will we have issues with it? 我的问题是,它会起作用还是我们会遇到问题?

Will this project run? 这个项目会运行吗?

Searching in google for ConcurrentHashmap compute, java 8 and source code level 1.7 did not give any info. 在谷歌搜索ConcurrentHashmap计算,java 8和源代码级别1.7没有提供任何信息。

If at all, this would require a lot of careful "manual" work. 如果有的话,这将需要大量仔细的“手动”工作。

When you look at this question for example, you can find that there are various different ideas how people want to enable "stream based" functional programming with Java 7. Maybe, after doing a lot of research, you might be able to find similar things regarding such "enhanced collection" features. 例如,当您查看这个问题时 ,您会发现人们想要如何使用Java 7启用“基于流”的函数式编程有各种不同的想法。也许,经过大量的研究,您可能能够找到类似的东西关于这种“增强的收藏”功能。

But then, all of that might be quite fragile . 但是,所有这些都可能非常脆弱 The fact that some examples might work fine wouldn't mean that you would be able to run a large production code base on a Java 7 VM. 一些示例可能正常工作的事实并不意味着您将能够在Java 7 VM上运行大型生产代码库。

Thus more of a non-answer here: be careful how to invest your time and energy. 因此,更多的答案在这里:小心如何投入时间和精力。 Instead of trying to backport libraries to Java 7, rather look into moving your whole project onto Java8 at least. 而不是尝试将库反向移植到Java 7,而是考虑将整个项目移动到Java8上。 Especially keeping in mind that the release cadence for Java has changed significantly, and going with outdated Java versions for many years is simply even less desirable compared to a few years ago. 特别要记住的是,Java的发布节奏已经发生了很大的变化,与几年前相比,使用过时的Java版本已经不那么令人满意了。

Well, the simple answer is that it will not work. 嗯,简单的答案是它不起作用。 The target runtime will not have the updated API (ie, the compute*** methods won't be on the version of Map that Java 7 has). 目标运行时将没有更新的API(即, compute***方法将不在Java 7的Map版本上)。

So if you deploy that code, the runtime will understand the class version, but will raise NoSuchMethodError and similar errors. 因此,如果部署该代码,运行时将理解类版本,但会引发NoSuchMethodError和类似错误。

In addition to this, there are many reasons for upgrading your runtime. 除此之外,升级运行时有很多原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM