I am trying to sort an array of objects of type Name. Name is a class that I defined. When I call the sort function, I need to pass the comparison function to sort. I wrote two
comparison functions. Here they are:
The first one works. Second one does not. The second one does not print: bad input. When I use the second one, I get the following error messages:
Exception in thread "main" java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.ComparableTimSort.mergeHi(ComparableTimSort.java:866)
at java.util.ComparableTimSort.mergeAt(ComparableTimSort.java:483)
at java.util.ComparableTimSort.mergeCollapse(ComparableTimSort.java:406)
at java.util.ComparableTimSort.sort(ComparableTimSort.java:213)
at java.util.Arrays.sort(Arrays.java:1246)
at Test2.main(Test2.java:84)
C:\Users\rsher\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
Here is how the class Name is defined:
It is a generic class and it is not public. Does this matter?
Thanks,
Bob