private static String name = "demo";
private static String name;
static {
name = "demo";
}
As shown in the above code, what is the difference between the two writing methods, or what are the advantages and disadvantages of each.
淡淡烟草味2017-05-18 10:46:30
There is no difference in the result, but you can write other code in the code block, such as stuffing data into the map.
某草草2017-05-18 10:46:30
In the static code block, you can assign values to more variables and other operations. It is generally used for initialization, such as loading static resource images when the game is loaded.
PHPz2017-05-18 10:46:30
There is a small difference: in the same class, the initialization of static properties is completed before the static initialization block