@Override
    public int compare(Method a, Method b) {
      int cmp = a.getName().compareTo(b.getName());
      if (cmp != 0) {
        return cmp;
      }
      Class<?>[] aparams = a.getParameterTypes();
      Class<?>[] bparams = b.getParameterTypes();
      if (aparams.length != bparams.length) {
        return aparams.length - bparams.length;
      }
      if (!Arrays.equals(aparams, bparams)) {
        return Arrays.toString(aparams).compareTo(Arrays.toString(bparams));
      }
      Class<?> aret = a.getReturnType();
      Class<?> bret = b.getReturnType();
      if (aret == bret) {
        return 0;
      }

      if (aret.isAssignableFrom(bret)) {
        return -1;
      }
      return +1;
    }
A comparator that defines a total order so that methods have the same name and identical
signatures appear next to each others. The methods are sorted in such a way that methods which
override each other will sit next to each other, with the overridden method first - e.g. Object
getFoo() is placed before Integer getFoo(). This makes it possible to determine whether a
method overrides another one simply by looking at the method(s) that precedes it in the list.
(see eliminateCovariantMethods).
geode-core/src/main/java/org/apache/geode/management/internal/MXBeanProxyInvocationHandler.java