Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

forName method with reference to the static block

 
Vishwadeep Aggarwal
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sun has provided one forName method as

forName(String cName, boolean b,ClassLoader load)

Q: My question is if i will pass the boolean parameter as false then is there any chance that the static block of the class which is going to be loaded using forName method will not going to be executed. Also what is the actual purpose of the second boolean parameter in the forName(String cName, boolean b,ClassLoader load) method?
 
Tony Docherty
Bartender
Posts: 2958
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If b is false then the loaded class will not be initialized unless it has previously been loaded and initialized. So if forName is called and the class hasn't been previously initialized then the static initializer block(s) will not be called but it will get called when you first attempt to use the class.
It's purpose is so you can load a class without having to immediately initialize it - ie you delay the initialization until a future time when the class is first used.
 
Vishwadeep Aggarwal
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic