Comparable
contract specifies that e.compareTo(null)
must throw NullPointerException
.
From the API:
Not
Is it ever a good idea to even have to sort a List containing null elements, or is that a sure sign of a design error?
Well, it probably doesn't make sense for the list to contain a null Object, but maybe your List contains a "business object" and you can sort on different properties of the business object, some of which may contain nulls.
Is this an acceptable use of a Comparator
The BeanComparator allows you to sort on a propery in a business object even if the property contains null, so I would have to say it is an acceptable use of a Comparator.