Overview of JDK 8 Support in NetBeans IDE

Lambda expressions address the bulkiness of anonymous inner classes by expressing the machinery of anonymous inner classes more compactly.

The general syntax of a lambda expression consists of a set of parameters, an arrow token, and a function body (either a single expression or a statement block):

(int a, int b) -> a * a + b * b;

NetBeans IDE detects pre-lambda expressions and displays the hints in the Editor proposing to turn such constructs into lambda expressions.

For example, the AnagramGame project features a pre-lambda construct in the Anagrams.java file as shown in the screenshot below.

After you click the light bulb in the margin or press Alt-Enter, the IDE shows the Use Lambda hint with a set of options available:

If the Use Lambda hint is selected, the IDE converts the anonymous inner class into a lambda expression.

If you choose the Run Inspect on option, the IDE displays the Inspect dialog box that allows to run a single Convert to Lambda inspection on the specified file.

For more information on initiating the Inspect operation in the IDE, see Using Hints in Source Code Analysis and Refactoring in Developing Applications with NetBeans IDE.

After you press the Inspect button to launch the inspection, the IDE identifies all the pre-lambda constructs in the file and displays them in the Inspector window.

If you choose the Run Inspect&Transform on option, the IDE displays the Inspect and Transform dialog box that allows to run a single Convert to Lambda inspection (or a selected configuration) on the specified code and refactor it if needed.

For more information on initiating the Inspect and Transform operation, see Using Hints in Source Code Analysis and Refactoring in Developing Applications with NetBeans IDE.

Xổ số miền Bắc