@Override
    public int compare(T o1, T o2) {
        if (o1 == o2) {
            return 0;
        } else if (o1 == null || o2 == null) {
            return o1 == null ? 1 : -1;
        }
        Class<?> o1c = o1.getClass();
        Class<?> o2c = o2.getClass();
        if (o1c == o2c) {
            return compareSameType(o1c, o1, o2);
        } else {
            // We use toString() representation instead of the class this should be
            // stable across invocations
            int diff = o1c.toString().compareTo(o2c.toString());
            // System.hashCode is pretty bad on some platforms, so we might get collision
            // In which case we find a unique id in CLASS_HASHCODE_COLLISION
            if (diff == 0) {
                // HMM different name, but same digg, anonymous class??
                throw new Error(o1c.toString() + ", " + o2c.toString().hashCode());
            }
            return diff;
        }
    }