wood burning stoves 2.0*
The moose likes Java in General and the fly likes Doubt in reflection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Doubt in reflection" Watch "Doubt in reflection" New topic
Author

Doubt in reflection

Shridhar Raghavan
Ranch Hand

Joined: May 27, 2010
Posts: 71
This is the signature of a method in a utility class.

Now given below is another hierarchy



Both with 1 & 2 i get an error
// The method (in the util class) select(Class<Object> clazz) is not applicable for the arguments select(<Class<capture#1-of ? extends BaseEntity>)

[Edit - added code tags - MB]
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4339
    
    7

You're not passing in a Class<Object> - the generic part is wrong. Try declaring the method with Class<?> instead.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Or perhaps even better, add a method generic type:
If you provide BaseEntity.class the result will be a List<BaseEntity>, etc.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
Don't get me started about those stupid light bulbs.
 
subject: Doubt in reflection
 
Similar Threads
Creating a more generic DAO (no hibernate) - A good Riddle
Object Run time typecasting
jdk1.6
JPA/Hibernate: @GeneratedValue doesnt work
How to keep variable value alive in JSF