关于initializer的问题,详情请进
英文不是很好,谁能帮忙解释一下下面这段话,并对应3个情况写3个例子看看?谢谢
Initializers are used in initialization of objects and classes and to define constants in interfaces. These initializers are :
1. Static and Instance variable initializer expressions.
Literals and method calls to initialize variables. Static variables can be initialized
only by static method calls.
Cannot pass on the checked exceptions. Must catch and handle them.
2. Static initializer blocks.
Used to initialize static variables and load native libraries.
Cannot pass on the checked exceptions. Must catch and handle them.
3. Instance initializer blocks.
Used to factor out code that is common to all the constructors.
Also useful with anonymous classes since they cannot have constructors.
All constructors must declare the uncaught checked exceptions, if any.
Instance Initializers in anonymous classes can throw any exception.(?)