Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dynamic class loading and generics

 
jay vas
Ranch Hand
Posts: 407
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys :

I have a class :

class A<T> { }

and I want to have a dynamic call to
T's constructor, i.e.

class A<T> { public T dynamic() {return T.class.newInstance(); } }

So my question is, how can I create an instance of a generic class
on the fly ?

Thanks!

Jay
 
Jean-Francois Briere
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way would be to do:

Regards
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic