G
Gyoergy Magoss
Hi,
I have a question regarding interfaces and constants.
I have defined a constant within an interface :
public interface InitInterface {
public final static boolean INITIALIZED = Initializer.initAll() ;
}
The main thing is. I want Initializer.initAll() to run autmatically
when a class is loaded, that implements this interface , e.g.
public class InitializerTest implements InitInterface {
public InitializerTest() {
super() ;
}
}
Alas the constant is not initialized when loading the class into the
classloader but rather when I first access the constant, e.g. by
adding the line
System.out.println("Initialized : " + INITIALIZED);
(by the way as soon as I do that and there are several constants in
the interface, all of them not only the one accessed are
initialized...)
to the constructor. My question : Is there a way to force a VM to
initialize the constants during class loading ?
Thanks
György
I have a question regarding interfaces and constants.
I have defined a constant within an interface :
public interface InitInterface {
public final static boolean INITIALIZED = Initializer.initAll() ;
}
The main thing is. I want Initializer.initAll() to run autmatically
when a class is loaded, that implements this interface , e.g.
public class InitializerTest implements InitInterface {
public InitializerTest() {
super() ;
}
}
Alas the constant is not initialized when loading the class into the
classloader but rather when I first access the constant, e.g. by
adding the line
System.out.println("Initialized : " + INITIALIZED);
(by the way as soon as I do that and there are several constants in
the interface, all of them not only the one accessed are
initialized...)
to the constructor. My question : Is there a way to force a VM to
initialize the constants during class loading ?
Thanks
György