• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to call static block without creating initiating a class

 
Bk Jacky
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rancher,

I have some classes with static blocks(having some variables in side).I want to initiate variables inside static block without creating object of that particular class. I know that i have to load a class in the memory but how?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several ways to load a class without creating an instance of the class. One simple, direct method is this:

Class.forName("com.the.ClassName");

Just calling the static "forName()" method in java.lang.Class, passing the class's name as a String, will load that class for you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic