Why does Java not support automatic up-casting for template argument types?
For example, the following class will not compile unless the newly created Derived
instance will be manually casted to a Base
instance:
public class Example implements Iterable<Base> {
@Override
public Iterator<Base> iterator() {
return Arrays.asList(new Derived()).iterator();
}
private class Base {
}
private class Derived extends Base {
}
}