28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 10 ■ Directing the Cast of Actors: Creating a Casting Director Engine and Creating the Bagel Actor Class<br />

the comma delimited List using the .asList() method called off the Arrays class reference, again passing the Actor...<br />

comma delimited list named actors into the method. This is done using the following <strong>Java</strong> method seen in Figure 10-4:<br />

public void removeCurrentCast(Actor... actors) {<br />

CURRENT_CAST.removeAll( Arrays.asList(actors) );<br />

}<br />

Now all you have left to code is a simple .resetCurrentCast() method, which invokes the .clear() method call:<br />

public void resetCurrentCast() {<br />

CURRENT_CAST.clear();<br />

}<br />

Next let’s take a look at one more issue in our CastingDirector.java code thus far, and then we can move on.<br />

NetBeans Optimization Suggestions: Making a List Data Store Object Final<br />

As you can see in Figure 10-5, your code is error-free, but is not warning free, so let’s take a look at what NetBeans<br />

wants us to do to the code that relates to our CURRENT_CAST List data store object. I used the mouse-over<br />

work process, and popped up the pale yellow hints message, which informed me that the CURRENT_CAST data<br />

field (variable, which is an object) can be marked as final, using the <strong>Java</strong> final keyword. If we were to do this, the<br />

basic <strong>Java</strong> 8 syntax for the new declaration and instantiation statement for the CURRENT_CAST object will be<br />

written as follows:<br />

private final List CURRENT_CAST = new ArrayList();<br />

Figure 10-5. Mouse-over yellow warning highlight under CURRENT_CAST, and use the Alt-Enter dialog to fix problem<br />

216<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!