This discussion is archived
10 Replies Latest reply: Aug 23, 2010 12:28 PM by 653909 RSS

wildcard capture problem please help

653909 Newbie
Currently Being Moderated
I have this method:
public <T extends X> T getX(Class<T> klass)
and the following client code:
public void utilize(Class<?> klass){
            Object o;
            if (X.class.isAssignableFrom(klass)) {
                o = getX(klass);
            } else {
                o = whateverDefaultObject();
     // ...
The point is if the klass is a subclass of X then use the getX method.

The problem is that I am getting an error stating: required class of X, found class of capture of ?

How can this be solved ?
In the client method body the klass is guaranteed to be correct because of the if clause.
Any help is keenly appreciated. Thanks