[英]Implement an interface that extends comparable
So I have an interface Foo is constructed like: 所以我有一个接口Foo构造如下:
public interface Foo<T extends Comparable<? super T>>
and I'm trying to implement Foo in my class bar like: 我正在尝试在我的班级栏中实现Foo,例如:
public class Bar<T> implements Foo<T>
but I get getting the error type argument T#1 is not within bounds of type-variable T#2
但我得到错误type argument T#1 is not within bounds of type-variable T#2
but when I try to implement Foo as: 但是当我尝试将Foo实现为:
public class Bar<T> implements Foo<T extends Comparable<? super T>>
I get > expected
and <identifier> expected
我得到> expected
和<identifier> expected
Your syntax is a bit off. 您的语法有些偏离。 Try moving the bounds to the declaration of T
as in this: 尝试将边界移动到T
的声明中,如下所示:
public class Bar<T extends Comparable<? super T>> implements Foo<T> {
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.