I'm trying to understand why this code won't compile.
I've got a class implementing an interface. The last method won't compile for some reason.
It will not simply allow me to cast the set as a set, but does allow it to return the single object fine.
Can someone please explain to me why this is? thanks.
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;
}
}