10 Replies Latest reply on Aug 23, 2010 7:28 PM by sandstorm_sh

    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