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

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -