Package Initialization in Java -


i'm building java package , need initialization code called in order package work properly. package being wrapped .jar, , have no control on user calling when import package application. rather having them need call initialization method before can start using package, there way method called under hood?

i'd mention static { } approach won't work, need code called 1 time regardless of objects in package being utilized.

no, there no such method on package level.

to achieve can add

static {    .... } 

block each of classes , have static block call common initializer.

for example:

package a.b; class x {   static {      a.b.static.init();   } }  class y {   static {      a.b.static.init();   } }  class static {   static void init() {     ... init code goes here ...   } } 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -