gpt4 book ai didi

java - 实现一个扩展 comparable 的接口(interface)

转载 作者:行者123 更新时间:2023-11-30 08:12:23 25 4
gpt4 key购买 nike

所以我有一个接口(interface) Foo 的构造如下:

public interface Foo<T extends Comparable<? super T>>

我正在尝试在我的类栏中实现 Foo,例如:

public class Bar<T> implements Foo<T>

但我收到错误 type argument T#1 is not within bounds of type-variable T#2

但是当我尝试将 Foo 实现为:

public class Bar<T> implements Foo<T extends Comparable<? super T>>

我得到 > expected<identifier> expected

最佳答案

你的语法有点不对。尝试将边界移动到 T 的声明中,如下所示:

public class Bar<T extends Comparable<? super T>> implements Foo<T> {
...
}

关于java - 实现一个扩展 comparable 的接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30520973/

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