10 Replies Latest reply: Aug 23, 2010 2:28 PM by sandstorm_sh RSS

    wildcard capture problem please help

      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