Java 8 Lambdas不起作用,Java 8中的所有其他工作都可以 [英] Java 8 Lambdas don't work, everything else from Java 8 works though

查看:130
本文介绍了Java 8 Lambdas不起作用,Java 8中的所有其他工作都可以的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现Java 8现已正式发布。似乎我需要Eclipse Luna 4.4才能工作。所以我下载了Luna并安装了它。我还从我的其他Eclipse导入了所有项目,一切都按预期工作。当我想尝试Java 8时,我很快发现我需要先安装它。安装完成后,我设法将JRE 8更改为默认值。

I found out that Java 8 is officially released now. It seems that I need Eclipse Luna 4.4 for it to work. So I downloaded Luna and installed it. I also imported all my projects from my other Eclipse, everything worked as expected. When I wanted to try Java 8, I quickly found out I needed to install it first. After I installed it I managed to change JRE 8 to the default.

我的问题是:为什么我可以使用新的日期&时间API,但我不能使用新的Lambda表达式?

My question is: Why can I use the new date & time API, but I cannot use the new Lambda Expressions?

一些可能有用的信息:


  • 我正在使用Mac

  • 我非常确定时间API是有效的(即使是小型Java Doc Box也说明是自1.8以来)

这可能与我没有安装包含Java 8的Eclipse有关吗?

Could it have something to do with the fact that I didn't install Eclipse with Java 8 included?

推荐答案

首先,您不需要使用Luna - 这是一个功能补丁Kepler 工作正常。

Firstly, you don't need to use Luna - there's a feature patch for Kepler which works fine.

其次,Java Compiler对话框的源兼容性部分必须为1.8。否则,即使您被允许使用Java 1.8的功能,您也将无法使用语言功能。 (这不仅仅是lambdas - 有方法引用,接口中的静态方法,以及默认方法。)这里是看的地方:

Secondly, the "source compatibility" part of the Java Compiler dialog has to be 1.8. Otherwise even though you're allowed to use the library features of Java 1.8, you won't be able to use the language features. (It's not just lambdas - there's method references, static methods in interfaces, and default methods for example.) Here's where to look:

想要<很少见使用1.8中的库功能,但保持源/类文件与1.7或更早版本的兼容性,但我想如果你编写需要在各种JRE上运行的代码可能会有用,但是你可能有一些需要Java的功能实现1.8并且不会在早期的JRE上使用。

It would be rare that you'd want to use library features from 1.8 but keep source/classfile compatibility with 1.7 or earlier, but I guess it could be useful if you were writing code that needed to run on various JREs, but you could have some feature implementations which required Java 1.8 and just wouldn't be used on earlier JREs.

这篇关于Java 8 Lambdas不起作用,Java 8中的所有其他工作都可以的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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