| Author |
about static final
|
Edward Chen
Ranch Hand
Joined: Dec 23, 2003
Posts: 758
|
|
Hi, I want to define some static final variables so that they will be loaded at first time when the class is up. Like this: static final ImageIcon icon = new ImageIcon("d.gif"); static final Vector vec = new Vector(); Question 1. How and where can I add the icon into vec so that the data will be added into vector at class load first time ? vec.add(icon); // could be loaded up at first time. Question 2: When the static final could be loaded up ? for example so, VecA will be created before main method or after ? VecB will be created before methodCall() or after ? In my understanding, both VecA and VecB should be created before A's main method. Am I right ? Thanks
|
 |
Dun Dagda
Ranch Hand
Joined: Oct 12, 2004
Posts: 54
|
|
Would enclosing the variables you want to initialise at class load time in a static initializer block help? static { // list of things you want to do }
|
SCJP 1.4<br />SCWCD (in progress)
|
 |
 |
|
|
subject: about static final
|
|
|