Where applicable, proposals can be excluded from the transformation and then, when the user clicks “Do Refactoring,” all proposals that are included are transformed to use lambdas.
In each case, a ‘before’ and an ‘after’ are shown in a Diff window. The user can examine each proposal for transformation. The result of the scan is shown in the Refactoring window.įigure 5: The result of the scan, as shown in the Refactoring window The user can specify a scope within which NetBeans should perform a search for anonymous inner classes that are able to be converted to use lambda expressions:Ī scan throughout the specified scope is then performed by NetBeans.
Because NetBeans is able to identify code segments eligible for conversion to use lambdas, it includes batch processing tools to speed up the conversion process significantly. Without them, converting code becomes an error-prone process and learning about new code constructs can become a frustrating process.Īiding the adoption of new code constructs is a criticial task of tool providers such as NetBeans, which is a task it has taken up over the years with aplomb. When learning about new constructs, such as lambdas, tools such as these yellow lightbulb hints are essential. The code is tighter, simpler, modernized, and more idiomatic than it was before. That is, a lambda had been added to the code, which has been restructured to hold less ‘boilerplate code’ than before:įigure 3: The result of clicking the lightbulb Here is the result, when the user clicks the yellow lightbulb hint shown above.
For example, below you see a yellow lightbulb hint that appears in the sidebar, prompting the user to allow NetBeans to transform the existing code construct, an anonymous innner class with a single abstract method, to use a lambda expression: NetBeans 8 automatically recognizes code constructs that can be changed to use lambdas. Moreover, using lambda expressions instead of the clunky and problematic anonymous inner classes inherent to Java makes for much cleaner code. New programmers to Java will pick up the language more quickly if it uses constructs familiar to other common programming languages hence, the introduction of lambdas helps increase the likelihood of Java adoption amongst the new ‘cool kids’ in the programming world. Lambdas are very well established in most, possibly even all, modern programming languages and Java was beginning to look a bit stale in their absence. The parameters are shown on the left, and the method body is shown to its right. What is a lambda? Briefly put, a lambda is an expression separated by an arrow. As the prime driving force of Java 8 is lambdas, so too underpinning NetBeans 8 are tools simplifying the process of using lambdas in new Java code, as well as tools for the probably even more significant task of migrating existing Java code to make use of lambdas. It is for that reason that the 8th version of Java was released hand in hand with the 8th version of NetBeans. Without tools, Java is unusable and, because competing IDEs have their own separate release cycles, NetBeans continues to lead the pack in being tightly aligned with new releases of Java and being most closely associated as the purest IDE for working with the Java language. By consistently positioning NetBeans as the “official IDE for the Java platform,” Sun and Oracle have created a unique place for NetBeans, whereby when a new version of Java is released, a related release of NetBeans is automatically pushed out the door. NetBeans 8 is the culmination of years of development work, initially under the leadership of Sun Microsystems and more recently that of Oracle.