Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Cost of Class.forName()  RSS feed

 
mohamed zafer
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello There,
How efficient is the usage of
Class class = Class.forName("MyClass");
class.getInstance();
to create a class dynamically.
Mohamed Zafer
 
Thomas Smets
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's much slower than static instaciation but ... it's dynamic as you said !
You could create a little script creating thousands of classes (see below) & instanciating them one after the other ?
Or just try to access all the instances from the java / javax package.
Perl or Python are good at that
In the example here below, I used innerclasses but I am not sure it is the best approaches.
If you can do it also with normal classes.
Rgds,
Thomas,

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!