Java Generics restrict to interface

后端 未结 3 2468
时光取名叫无心
时光取名叫无心 2021-02-20 05:44

I\'m not sure if this is possible or not, but what I want to accomplish is this:

public static  B makeB(A thing) {...}
         


        
3条回答
  •  暖寄归人
    2021-02-20 06:16

    If SomeClass is always a class, the A in can only be an interface, because there is no multiple inheritance in Java. The only way & A can be satisfied is if A is an interface.

提交回复
热议问题