Reputation: 347
So I have a public class and within this class are several public functions including a static method.
public class TestVocabValidator {
static { getEnumList( vocabList.values() ); }
public static Iterator<String> getVocabEntries(String x) {
return null;
}
}
Whenever I call on the function getVocabEntries()
, does the static method get called automatically?
Upvotes: 0
Views: 715
Reputation: 48404
The static blocks (e.g. static {...}
) are executed once, when the class' name is referenced and the class is loaded.
The static methods (e.g. getVocabEntries
) are executed every time they are invoked.
Upvotes: 3
Reputation: 13596
Not whenever you call that static method. The first time that class is loaded, in this case the first time you call that method, the static block is called.
Upvotes: 1