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.
拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...
There is no difference as far as the intermediate code is concerned
There is no difference in the result, but you can write other code in the code block, such as stuffing data into the map.
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.
There is a small difference: in the same class, the initialization of static properties is completed before the static initialization block
There is no difference as far as the intermediate code is concerned
There is no difference in the result, but you can write other code in the code block, such as stuffing data into the map.
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.
There is a small difference: in the same class, the initialization of static properties is completed before the static initialization block