Consider this code:
public interface Foo extends Comparable<Foo> {}
public enum FooImpl implements Foo {}
Due to the restrictions of type erasure, I receive the following error:
java.lang.Comparable cannot be inherited with different arguments:
<Foo>
and<FooImpl>
I have the following requirements:
FooImpl
needs to be an enum, because I need to use it as a default value in annotations.I already tried using generic bounds in the interface, but this is not supported in Java.
Enums implement Comparable, so FooImpl ends up extending Comparable twice with incompatible arguments.
The following will work:
public interface Foo<SelfType extends Foo<SelfType>> extends Comparable<SelfType> { ... }
public enum FooImpl implements Foo<FooImpl> { ... }
Enum already implements comparable so you can't override it.
A general answer regarding why-would-an-enum-implement-an-interface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With