Solved

JDk1.5.0 Class<T> problem??

Posted on 2006-10-19
5
182 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ejb on wildfly 5 64
Adding multiple JVM environments to RedHat 6 7 84
CSV file parsing thru Java 13 54
Overriding a method 3 14
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

752 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