reset password
Author Message
RandomAccess
Posts: 101
Posted 03:00 Nov 01, 2017 |

I was trying to set an action to my button to test it out, but unfortunately the code reads the lambda expression as an error. The following was the specific code:

newGame.setOnAction(e -> System.out.println("You clicked 'New Game'"));

for some reason it keeps reading the "e" and the "->" as errors. I tried looking up tutorials online, and I think it may be because I'm not on java version 8? In any case, I found the ways to solve it online a bit hard to read and understand, so I was wondering if someone here could help me.

jingchao
Posts: 25
Posted 05:50 Nov 01, 2017 |

you missing {},

it is

newGame.setOnAction(e -> ({ System.out.println("You clicked 'New Game'")});

instead of 

newGame.setOnAction(e -> System.out.println("You clicked 'New Game'"));

RandomAccess
Posts: 101
Posted 07:30 Nov 01, 2017 |

Yeah I tried it that way too, same result. In fact that’s what I tried at first and changed it to its present form to see if it would produce better results. Still got the same error.

jingchao
Posts: 25
Posted 08:32 Nov 01, 2017 |

I've seen a tutorial and it mentioned in some IDE you have to set up for lambda expression

RandomAccess
Posts: 101
Posted 11:31 Nov 01, 2017 |

Can you link me the tutorial?

jingchao
Posts: 25
Posted 11:35 Nov 01, 2017 |

here is the link, but its just about how to use lambda expression

https://www.youtube.com/watch?v=QGGE0WsUslc&t=135s