当前位置: 技术问答>java相关
关于initializer的问题,详情请进
来源: 互联网 发布时间:2015-03-13
本文导语: 英文不是很好,谁能帮忙解释一下下面这段话,并对应3个情况写3个例子看看?谢谢 Initializers are used in initialization of objects and classes and to define constants in interfaces. These initializers are : 1. Static and Instance...
英文不是很好,谁能帮忙解释一下下面这段话,并对应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.(?)
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.(?)
|
Initializer 常用于初始化类和对象,也可用于接口中的常量定义。
这些Initializer主要分以下几种:
1。静态实例的Initilizer表达式
2。静态Initalizer包
3。实例Initalizer包
这些Initializer主要分以下几种:
1。静态实例的Initilizer表达式
2。静态Initalizer包
3。实例Initalizer包