Is there a difference between the generic bounds “Enum & Foo” and “Enum<? extends Foo>”

后端 未结 4 751
攒了一身酷
攒了一身酷 2020-12-09 10:35

Are these two (valid) generic bounds:

 & MyInterface>
>

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-09 10:55

    Since the second one relies on the special fact that Java enums are implemented as MyEnum extends Enum, I would prefer the first one, which doesn't rely an such assumptions and states your constraints explicitly.

提交回复
热议问题