Generics usage

Can anyone tell me the difference between :

public <Textends MyClass> T getMyClass(){}

and

public Class<?extends MyClass> getMyClass(){}

Im trying to use generics and I'm having a problem when I try to use

the subclass of MyClass that is is returned by my

generified method getMyClass(). The specific problem is

that I get compile Time errors when I try to cast to the correct sub-type

of MyClass that is being used. I'm not sure if this is even possible

and the combination of the two different constructs above(which seem

synonomous to me) are both confusing me.

I guess my question is, more or less, if I have

private Class<?extends MyClass> myObj;

public Class<?extends MyClass> getMyObj(){return myObj}

does this force me to use the returned object as if it were an instance of MyClass? Do I have the wrong idea on the uses of generics?

Thanks for any help

[1475 byte] By [newbie85a] at [2007-10-2 18:26:21]
# 1

<T extends MyClass>

You can use T in the class/method definition.

You can't use a ?.

Try and study this code -- compiles and runs just fine.

public class GeneTest{

private Class<? extends MyClass> myObj;

public GeneTest(){

myObj = MyClass.class;

}

public Class<? extends MyClass> getMyObj(){

return myObj;

}

public static void main(String[] args){

GeneTest gt = new GeneTest();

System.out.println(gt.getMyObj());

}

}

class MyClass{

}

hiwaa at 2007-7-13 19:47:28 > top of Java-index,Java Essentials,New To Java...