Double generic constraint on class in Java: extends ConcreteClass & I

本秂侑毒 提交于 2019-12-04 02:54:50

The simplest way I can see of resolving the Java code is to make Class2 an interface.

You cannot constrain a type parameter to extends more than one class or type parameter. Further, you can't use super here.

This code compiles here fine:

interface Interface1 {}

class Class2 {}

class Class1<I extends Interface1, T extends Class2 & Interface1> {}

Why do you need the I type there when you assume only Interface1 anyway? (you won't know anything more in your class about I than it extends Interface1)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!