Next we would like to stop someone from constructing the ArrayShuffler
class,
since they should be calling the static
method instead. The first step is to
add a constructor and make it private
, like this:
private ArrayShuffler() {}
When we now try to run our application, we find several places where we called
shuffle on an object of type ArrayShuffler
, rather than on the class. We fix
those to instead call the static
method.
Note that when we tried running the code again, it now tried to compile the test classes and those also failed. The tests were not compiled together with the main game, since they are a different part of the system.
We again replace the new ArrayShuffer()
code with calling the static method on
the class with ArrayShuffler.shuffle()
.
Everything works, so we commit our code.
We hope you enjoyed this tutorial. If you did, you will also enjoy our courses. We suggest you start with Extreme Java - Advanced Java, followed by Extreme Java - Concurrency Performance for Java 8.
We deliver relevant courses, by top Java developers to produce more resourceful and efficient programmers within their organisations.
We can help make your Java application run faster and trouble-shoot concurrency and performance bugs...