Java generics parameter bounding to any of a range of types

后端 未结 5 1532
一向
一向 2020-12-10 12:26

Is there a syntax or workaround to constrain a generic type parameter to any of a range of types?

I am aware that you can constrain a type to be all

5条回答
  •  失恋的感觉
    2020-12-10 13:00

    No. It wouldn't make any sense unless all the types had a non-empty union type, e.g. an interface they all implemented, or a base class they all extended, in which case you just specify the union type.

提交回复
热议问题