Java:静态初始化块什么时候有用?
2022-08-31 08:55:49
块内的初始化有什么区别:static
public class staticTest {
static String s;
static int n;
static double d;
static {
s = "I'm static";
n = 500;
d = 4000.0001;
}
...
和单独的静态初始化:
public class staticTest {
static String s = "I'm static";
static int n = 500;
static double d = 4000.0001;
....