Lambda is a new feature after JDK1.8, and I note that there was a problem when I first used lambda
The author USES versions: MyEclipse8.5, JDK1.8.0, and IDEA2018.2.5
When I run the following lambda code on MyEclipse, an error message appears:
The author USES versions: MyEclipse8.5, JDK1.8.0, and IDEA2018.2.5
When I run the following lambda code on MyEclipse, an error message appears:
package com.text;
public class Lambda {
public static void main(String[] args) {
Lambda lambda = new Lambda();
lambda.oldRunable();
lambda.runable();
}
public void oldRunable() {
new Thread(new Runnable() {
public void run() {
System.out.println("The old runable now is using!");
}
}).start();
}
public void runable() {
new Thread(()->System.out.println("It's a lambda function!")).start();
}
}
Code line 19 reports an error:
Multiple markers at this line
- Syntax error on tokens, Expression expected instead
- Syntax error on token(s), misplaced construct (s)
After a search on the Internet, there was no explanation for this anomaly, and then I decided to run IDEA for a try. It turned out that the same code IDEA was not wrong, so this is for record
The author estimates that it may be because the version of MyEclipse8.5 is too low, but the author has not changed the version of MyEclipse, and I will try it again in the future. You are welcome to comment on the upgraded version, thank you