What is the difference between assignment in static properties and assignment in static code blocks?
高洛峰
高洛峰 2017-05-18 10:44:30
0
4
623
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教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(4)
世界只因有你


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.

PHPzhong

There is a small difference: in the same class, the initialization of static properties is completed before the static initialization block

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template