I have a class with a bounded type parameter with nested wildcard bounded types. In the class I need to use the types of the bound nested parameters in multiple methods. Is there a way to define the wildcard bounded type as a generic type parameter instead or assign it to a generic variable name so that it can easily be referenced in multiple places?
The way the class is implemented now is like
class AbstractManager<F extends Filter<? extends Criteria<? extends Type>>>
{
protected void setFilter(F filter)
{
setCriteria(f.getCriteria());
}
protected <T extends Criteria<? extends Type>> void setCriteria(List<T> criteria)
{
}
protected <T extends Criteria<? extends Type>> void doSomethingWithCriteria(List<T> criteria)
{
...
}
}
which does not bound actually restrict the type of the list to the type of the Filter but is good enough in our situation. Ideally the type of the list would be restricted to the type of the filter using a construct that could bind the inferred type of the filter to a name much like a bounded type parameter on a method but at the class level instead.
Basically I would like to do something like
class <G extends Criteria<? extends Type> AbstractManager<F extends Filter<G>>
From what I know and can find, this is not possible, but I was hoping that maybe there was an obscure feature or new feature in java 7 that would make this possible. I know it is possible to specify a second type parameter like
class AbstractManager<F extends Filter<G>, G extends Criteria<? extends Type>>
but I do not want the child classes to have to specify G when the compiler can determine it.
The only possible option/solution I have been able to find is to have a shallow subclass with factory methods given in the solution to this question Nested Type Parameters in Java and in Java generics - use same wildcard multiple times