Search code examples
javaenumscomparable

Is "implements Comparable<Foo>" redundant for enums?


In the following example, is there any difference in behavior or allowed usages for the enum Foo with or without the implements Comparable<Foo>?

enum Foo implements Comparable<Foo> {
    a, b, c
}

I'm not interested in differences observable through reflection (e.g. by calling Foo.class.getInterfaces()), but if there are any more such differences you know of, please note them!


Solution

  • I would say it clearly is:

    public abstract class Enum<E extends Enum<E>>
            implements Comparable<E>, Serializable { ... }
    

    Any enum MyEnum is automatically Comparable<MyEnum>.