谁能解释一下这是什么意思?
Enum<T extends Enum<T>>
这似乎是一个循环定义,至少可以说我觉得它非常困惑。
最佳答案
有一个 good explanation in the Java Generics FAQ .
从结束位开始:
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).
(但我确实表示同情 - 递归泛型声明很痛苦。我的 Protocol Buffer 移植到 C# 更糟:它需要两个声明,每个声明都引用它们自己 和 ......我还没有找到简化它们的方法。)
关于java - 解释 Enum 声明中使用的泛型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/648188/