Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 java 泛型中,有没有办法告诉某个类型不是另一个类的子类或超类?我的意思是我们可以在某些关系层次结构上使用上限和下限。但是我们怎么能以其他方式做到这一点<? isNotASubTypeOf A>。
<? isNotASubTypeOf A>
所以你要
<T !extends Foo>
不……不能那样做
虽然这不能回答你的问题,但在这种情况下,我认为 Scala 中的模式匹配非常有用。你可以给他这样的东西。
typeVariable match { case A => //do whatever case B => //do whatever case _ => //do whatever