java 1.8 与 java 1.7 兼容性问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21402136/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 08:29:36  来源:igfitidea点击:

java 1.8 versus java 1.7 Compatibility Issue

java

提问by Tarun Chaudhary

I am using Java 1.7in my code, now i want to replace JAVA 1.7to JAVA 1.8.Is Java 1.8compatible to Java 1.7. ? Will it work as it before. i mean, all new features of Java 1.8 can be used in the existing piece of code?

Java 1.7在我的代码中使用,现在我想替换JAVA 1.7JAVA 1.8.IsJava 1.8兼容Java 1.7。? 它会像以前一样工作吗?我的意思是,Java 1.8 的所有新功能都可以在现有代码中使用吗?

采纳答案by Marko Topolnik

The existing piece of code will (ipso facto) not be using any new features of Java 8. If you have a piece of code which works1on Java version v, it will also work on all other versions v' > v. That is the long-standing promise of the Java platform.

现有的一段代码(事实上)不会使用 Java 8 的任何新特性。如果你有一段代码在 Java 版本v上运行1,它也可以在所有其他版本v' > v 上运行。这是 Java 平台的长期承诺。



1By "works" I mean "works as specified, using non-deprecated official JDK APIs".

1“工作”是指“按照规定工作,使用未弃用的官方 JDK API”。

回答by Mikkel L?kke

It depends.

这取决于。

Your question is a little unclear. "Will it work as before" and "All new features of Java 8 can be used in the existing piece of code" seem mutually exclusive.

你的问题有点不清楚。“它会像以前一样工作吗”和“Java 8 的所有新功能都可以在现有代码中使用”似乎是相互排斥的。

If you are using a Lambda Expression (Java 8 feature) you will not be able to compile using JDK7. Conversely if you are compiling using JDK7 you will not be able to use any of the new features in JDK8.

如果您使用的是 Lambda 表达式(Java 8 功能),您将无法使用 JDK7 进行编译。相反,如果您使用 JDK7 进行编译,您将无法使用 JDK8 中的任何新功能。

TL;DR: If you have to ask, it probably won't.

TL;DR:如果你不得不问,它可能不会。