Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static method without a name

In an Android example class theres this method:

static {        
    addItem(...);
}

When I reference the class, the items are indeed added. I never saw a method like this, a. how is this called and b. I suppose this method is called whenever the class is referenced (or the first time it is referenced)?

like image 853
fweigl Avatar asked Jun 05 '13 07:06

fweigl


1 Answers

This is called static initializer and the code inside it is invoked only once at class loading.

like image 137
Eng.Fouad Avatar answered Oct 12 '22 22:10

Eng.Fouad