java8工作,Java 8 Lambda的工作不起作用,Java 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.

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

Some info that might be useful:

I'm using a Mac

I'm very certain that the time API works (Even the small Java Doc Box says it's since 1.8)

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

解决方案

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

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:

rTwcy.png

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值