简体   繁体   中英

Static initializer block [on hold]

Initialization means storing a value inside the variable at the time of its declaration but in static block we have to declare that field before storing a value. As if we declare a static inside static block it shows error since the scope is local scope. And if declare a non static variable then it is in static block scope hence it is a local variable. So we have to declare the static field at class level scope. My question is that we are not storing the value during declaration rather after its declaration so its assignment. Then why is it called static initializer block?

By Carlos: "Initialization means storing a value inside the variable at the time of its declaration" - I discord, initialization can happen later on, IMHO (eg a field can be initialized in constructor). `static initializer block" is a block that initializes a class, so it is static; not to be confused with instance initializer block

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM