我们可以在方法(arraylist<?super t> list)中传递的arraylist的类型是什么?
public interface Fruits {}
public interface SweetFruitsInterface extends Fruits{}
public class FruitParty <T extends Fruits> {
public void getFruits(ArrayList<? super SweetFruitsInterface> fruitList) {
System.out.println("Lets get Fruit List");
}
}
,根据我的理解,我可以通过SweetFruitsInterface类型的阵列列表来调用此
public class SweetProducts {}
public class SweetFruits extends SweetProducts implements SweetFruitsInterface{}
现在
ArrayList<SweetProducts> sweetProductsArrayList1 = new ArrayList<>();
fruitsFruitParty.getFruits(sweetProductsArrayList1);
方法它给出编译器错误? 我可以知道这种甜产品是否不是SweetFruitsInterface的实现类别类别的超级
类
public interface Fruits {}
public interface SweetFruitsInterface extends Fruits{}
public class FruitParty <T extends Fruits> {
public void getFruits(ArrayList<? super SweetFruitsInterface> fruitList) {
System.out.println("Lets get Fruit List");
}
}
Now to call this method as per my understanding I can pass an arrayList of SweetFruitsInterface type but other than that we can pass super classes of implementation class of SweetFruitsInterface and so I try to create one implementation of SweeFruitsInterface as below:
public class SweetProducts {}
public class SweetFruits extends SweetProducts implements SweetFruitsInterface{}
now I call the method
ArrayList<SweetProducts> sweetProductsArrayList1 = new ArrayList<>();
fruitsFruitParty.getFruits(sweetProductsArrayList1);
But its giving compiler error?
May I know if this SweetProducts is not the super class of implementation class of SweetFruitsInterface , and if it is then why its not working..
I tested this with class scenario where T is super , but i wanna understand how this works for interface
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论