java - Get generic type of class at runtime -


how can achieve this?

public class genericclass<t> {     public type getmytype()     {         //how return type of t?     } } 

everything have tried far returns type object rather specific type used.

as others mentioned, it's possible via reflection in circumstances.

if need type, usual (type-safe) workaround pattern:

public class genericclass<t> {       private final class<t> type;       public genericclass(class<t> type) {           this.type = type;      }       public class<t> getmytype() {          return this.type;      } } 

Comments

Popular posts from this blog

sql - Time in datatime field -

javascript - How to split the success output from an Ajax post? -

java - sharing object across different classes -