code: public final int compareTo(E o) {
          Enum<?> other = (Enum<?>)o;
          Enum<E> self = this;
          if (self.getClass() != other.getClass() && // optimization
              self.getDeclaringClass() != other.getDeclaringClass())
              throw new ClassCastException();
          return self.ordinal - other.ordinal;
      }
docs: Compares this enum with the specified object for order.  Returns a
  negative integer, zero, or a positive integer as this object is less
  than, equal to, or greater than the specified object.
  
  Enum constants are only comparable to other enum constants of the
  same enum type.  The natural order implemented by this
  method is the order in which the constants are declared.