JDk1.5.0 Class<T> problem??

zollen
zollen used Ask the Experts™
on
I have a small program:
===============

public class TestMe
{
        public TestMe() {}
        public static void print (Class<TestMe> cls)
        {
        }
        public static void main (String [] args)
        {
                print(ABC.class);
        }
}

class ABC extends TestMe
{
        public ABC() {}
}

==========================
It fails to compile due to the following reason:

TestMe.java:12: print(java.lang.Class<TestMe>) in TestMe cannot be applied to (java.lang.Class<ABC>)
                print(ABC.class);

Any Idea of solving this little problem?????
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Try this:

public static void print (Class<? extends TestMe> cls)
Top Expert 2006

Commented:
Or leave the print method signature unchanged
But cast the class like this
print((Class<TestMe>) TestMe.class);
Top Expert 2006

Commented:
NO NO You want ABC, so my method is not correct
To generalise, if a Banana extends Fruit. Then a Baseket of Banana does not extend Basket of Fruit. To understand this in an agile/easier way, refer these links,

http://www.agiledeveloper.com/articles/GenericsInJavaPartI.pdf
http://www.agiledeveloper.com/articles/GenericsInJavaPartII.pdf

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial