我们可以在方法(arraylist<?super t> list)中传递的arraylist的类型是什么?

发布于 2025-02-06 12:57:15 字数 734 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文