• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about static final

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic