import java.util.Comparator; class NullComparator { private final Comparator real = null; private Comparator other; private Comparator another; NullComparator(Comparator real) { } public NullComparator thenComparing() { return new NullComparator<>(real == null ? other : another); } Comparator a() { return null; } Comparator b() { return null; } public NullComparator thenComparing1() { return new NullComparator<>(real == null ? a() : b()); } }