Game Development Reference
In-Depth Information
One of the interesting things that using lambda expressions does by “implicitly” de-
claring and using classes, such as the EventHandler class in the instances in this
chapter, is that it reduces the number of import statements in the top of your class
code. This is because if a class is not specifically used (its name written) in your code,
the import statement for that class does not have to be in place at the top of your code
with the other import statements.
Also, notice that the code-collapsing plus and minus icons in the left margin of
NetBeans are also gone! This is because a lambda expression is a basic Java code state-
ment, and not a construct, such as a method or inner class as it was before you conver-
ted it to a lambda expression. If you look at Figure 9-12 , your event handling code is
looking very clean and well-structured, and yet, in just over a dozen lines of code, it is
actually doing quite a lot for your game.
Next, let's take a look at your import statements code block (especially if you have
your import code block collapsed), since you had NetBeans 8 create lambda expres-
sions for you. Let's see if you have any unneeded imports!
Optimizing Import Statements: Remove the EventHand-
ler Class Import Statement
Click the + plus icon at the top-left of NetBeans and expand your import statement sec-
tion and see if you now have an unused import javafx.event.EventHandler statement
with wavy yellow underline warning highlighting underneath it. I have this, as you can
see in Figure 9-13 , and when I mouse-over it I get the “Unused Import” warning mes-
sage. I used the Alt-Enter work process to bring up the solutions options helper dialog,
and sure enough, there was a “Remove Import Statement” option. So NetBeans will
unwrite code for you as well as writing it for you! Pretty amazing feature!
 
Search WWH ::




Custom Search