没有警告的通用接口比较器
鉴于:
public interface PrimaryKey<Key extends Comparable> {
Key getKey();
}
和
public class PrimaryKeyComparator implements Comparator<PrimaryKey> {
public int compare(PrimaryKey first, PrimaryKey second) {
return first.getKey().compareTo(second.getKey());
}
}
此组合有效,但会给出有关原始类型的警告。我尝试了各种添加类型参数的方法,但我尝试的每种组合都会破坏代码。
Given:
public interface PrimaryKey<Key extends Comparable> {
Key getKey();
}
and
public class PrimaryKeyComparator implements Comparator<PrimaryKey> {
public int compare(PrimaryKey first, PrimaryKey second) {
return first.getKey().compareTo(second.getKey());
}
}
This combination works, but gives warnings about raw types. I've tried various ways of adding the type arguments, but every combination I've tried breaks the code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
Try this: