Here's an interface:
public interface Foo<T> extends Comparable<Foo<T>> {
...
}
And there are some classes implementing this interface:
public class Bar extends Something implements Foo<Something> {
public Vector<Foo<Bar>> giveBar() {
...
}
}
public class Boo extends SomethingElse implements Foo<SomethingElse> {
public Vector<Foo<Boo>> giveBoo() {
...
}
}
Now I want to keep a bunch of Foos (that may really be Foos or Boos) inside a vector.
Bar bar = new Bar();
Boo boo = new Boo();
Vector<Foo<?>> vector;
if (...)
vector = bar.giveBar();
else
vector = boo.giveBoo();
I get:
Type mismatch: cannot convert from Vector<Foo<SomethingElse>> to Vector<Foo<?>>
The same goes for:
Vector<Foo> vector;
if (...)
vector = giveBar();
else
vector = giveBoo();
Is a superclass that both Bar and Boo extend the only solution to this problem?