Click here to Skip to main content
15,742,357 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi every body, i got this one i don't know what to do, i search in the sun but don't have the answer about this

I want to write a generic method to use with every type, so when i write this method, it didn't work with the real type. So could anyone show me how to use "getClass" with type "T"

This is the method
public <T> T GetByID(int id) {
        return (T) m_Session.get(getClass(), id);
Nagy Vilmos 10-Nov-11 12:25pm    
Could you clarify what m_Session is please.

1 solution

Reflecting generics by Ian Robertson[^]

you might want to read that.
Share this answer
Comments 14-Nov-11 9:09am    
Thank you so much!!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900