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

后端 未结 2 1228
萌比男神i
萌比男神i 2021-02-19 23:17

Is there a way to define a generic constraint in Java which would be analogous to the following C# generic constratint ?

class Class1 where I : Interf         


        
2条回答
  •  再見小時候
    2021-02-19 23: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.

提交回复
热议问题