gpt4 book ai didi

java - 如何限制泛型类中允许为 "T"的类型?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:43:28 26 4
gpt4 key购买 nike

我有一个类(class) Foo<T> .怎么说我要T成为实现 BarInterface 的某个类?简单写class Foo<T implements BarInterface>不编译。

最佳答案

使用 extends 而不是 implements

关于java - 如何限制泛型类中允许为 "T"的类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3288053/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com