【发布时间】:2013-02-28 21:40:52
【问题描述】:
我试图理解为什么这段代码无法编译。
我有一个实现接口的类。最后一个方法由于某种原因无法编译。
它不仅允许我将集合转换为集合,而且允许它很好地返回单个对象。
有人可以向我解释这是为什么吗?谢谢。
public class Testing2 {
public SortedSet<ITesting> iTests = new TreeSet<ITesting>();
public SortedSet<Testing> tests = new TreeSet<Testing>();
public ITesting iTest = null;
public ITesting test = new Testing();
// Returns the implementing class as expected
public ITesting getITesting(){
return this.test;
}
// This method will not compile
// Type mismatch: cannot convert from SortedSet<Testing> to SortedSet<ITesting>
public SortedSet<ITesting> getITests(){
return this.tests;
}
}
【问题讨论】:
-
您会编辑您的问题以包含确切的编译器消息吗?编辑:另外,看起来测试实现了 ITesting?
-
是的,对不起。测试实现 ITesting
-
看起来像 stackoverflow.com/questions/897935/… 的副本
标签: java interface casting set