Code looks like this:
class AX {
static int[] x = new int[0];
static {
x[0] = 10;
}
}
I have never seen the use of static{}
before. What is this? A method?
Code looks like this:
class AX {
static int[] x = new int[0];
static {
x[0] = 10;
}
}
I have never seen the use of static{}
before. What is this? A method?
It's code that runs when the class initializes.
When the class is loaded and initialized, all the static blocks and initializers are run. This includes all the lines like this
static int[] x = new int[0];
that initialize a static field, and all the bits like this
static{
x[0] = 10;
}
that can contain more or less arbitrary code for initializing things.
They get run in the order that they appear in the source code.