April 2017
Beginner
504 pages
14h 11m
English
The modified Sort interface will look like this:
public interface Sort { void sort(SortableCollection collection); void setSwapper(Swapper swap); void setComparator(Comparator compare); }
This also means that we will need two new interfaces: Swapper and Comparator. We are lucky that the Java runtime already defines a Comparator interface that just fits the purpose. You may have guessed that from the following import statement:
import java.util.Comparator;
When you need something very basic, like a comparator interface, it is most probably defined in the runtime. It is advisable to consult the runtime before writing your own version. The Swapper interface, however, we will have to create.
package packt.java9.by.example.ch03; ...
Read now
Unlock full access