Explain the generics used in the Enum declaration

后端 未结 1 378
星月不相逢
星月不相逢 2021-01-19 15:51

Can someone please explain what this means?

Enum>

This seems like a circular definition, and I find it highl

相关标签:
1条回答
  • 2021-01-19 16:31

    There's a good explanation in the Java Generics FAQ.

    From the end bit:

    To sum it up, the declaration Enum<E> extends Enum<E>> can be decyphered as: Enum is a generic type that can only be instantiated for its subtypes, and those subtypes will inherit some useful methods, some of which take subtype specific arguments (or otherwise depend on the subtype).

    (I do sympathise though - recursively generic declarations are a pain. My protocol buffers port to C# is even worse though: it requires two declarations which each refer to themselves and each other... I haven't found a way of simplifying them.)

    0 讨论(0)
提交回复
热议问题