### Question:
NullComparator implements Comparator<T> { @Override public int compare(T o1, T o2) { if (o1 == null) { return o2 == null ? 0 : -1; } if (o2 == null) { return 1; } return underlying.compare(o1, o2); }  @Override int compare(T o1, T o2);  }### Answer:
@Test public void test() { Comparator<Integer> comparator = new NullComparator<>(Integer::compare); assertThat(comparator.compare(1, 2)).isEqualTo(Integer.compare(1, 2)); assertThat(comparator.compare(null, null)).isEqualTo(0); assertThat(comparator.compare(null, 1)).isLessThan(0); assertThat(comparator.compare(1, null)).isGreaterThan(0); }