Sometimes in my code I'd like to refer to (what I think of as) the implicit type in a generics heirarchy (basically the type implied by the first ? in the following).
public class Foo<BAR extends Bar<?>> {
public void t(BAR x) {
List l = new ArrayList();
Object baz = x.makeBaz(null);
l.add(baz);
x.setBazList(l);
}
}
public interface Bar<BAZ extends Number> {
public BAZ makeBaz(Object arg1);
public List<BAZ> getBazList();
public void setBazList(List<BAZ> baz);
}
For example in the above code would it be possible to replace the lines
List l = new ArrayList();
Object baz = x.makeBaz(null);
with something using generics?
I would prefer to avoid having to write:
public class Foo<BAZ extends Number, BAR extends Bar<BAZ>> {
public void t(BAR x) {
List<BAZ> l = new ArrayList<BAZ>();
BAZ baz = x.makeBaz(null);
l.add(baz);
}
}
since it feels unnatural to force this on the declaration of any derived classes.
I know the above is a bit contrived, but it's a lot simpler than trying to show the actual code I'm looking at.