Solved

JDk1.5.0 Class<T> problem??

Posted on 2006-10-19
5
183 Views
Last Modified: 2010-03-31
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?????
0
Comment
Question by:zollen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
shinobun earned 50 total points
ID: 17767212
Try this:

public static void print (Class<? extends TestMe> cls)
0
 
LVL 9

Expert Comment

by:shinobun
ID: 17767216
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 17767409
Or leave the print method signature unchanged
But cast the class like this
print((Class<TestMe>) TestMe.class);
0
 
LVL 14

Expert Comment

by:hoomanv
ID: 17767428
NO NO You want ABC, so my method is not correct
0
 
LVL 5

Expert Comment

by:kannan_ekanath
ID: 17772772
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
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question