Jeggy
Jeggy

Reputation: 1650

Backwards compatibility of lambda expressions?

Netbeans always suggests that I should use Lambda expressions, and I know lambda is something new. So I'm wondering if I convert the code to use lambda expression, will it work if I export it as a jar and send it to other people also those who don't have the newest Java installed, and if not what will happen when they run it?

enter image description here

And when making school projects, I'm sending the netbeans project, and there's a chance that the one that will test my code don't have the newest version. Do you think I should use lambda expressions?

I do like that cleaner and simpler code, but I want it to work everywhere also.

Upvotes: 2

Views: 437

Answers (1)

Simon Kuang
Simon Kuang

Reputation: 3940

If you are using it at school, that means that probably your teacher has Java 8 as well. Feel free to use lambda expressions if you feel that it makes your code shorter.

If you let Netbeans 8 convert that into a lambda expression, you'll get something like submitButton.addActionListener(e -> {doStuff();}). This is functionally equivalent. Literally by e -> {doStuff();} you mean "make me an object of a class with function of e that matches the argument type, ActionEvent, and has the body doStuff."

Lambda expressions are an extremely powerful (and cool) functional programming API in Java 8.

Upvotes: 2

Related Questions