繁体   English   中英

实现可扩展的接口

[英]Implement an interface that extends comparable

所以我有一个接口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> {
    ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM