Generic class that accepts either of two types

后端 未结 3 1127
猫巷女王i
猫巷女王i 2020-12-03 06:24

I want to make a generic class of this form:

class MyGenericClass {}

Problem is, I want to be acceptable for T to b

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 07:16

    No, there's nothing in Java generics to allow this. You might want to consider having a non-generic interface, implemented by FooIntegerImpl and FooLongImpl. It's hard to say without knowing more about what you're trying to achieve.

提交回复
热议问题