Instance Initializers
An instance initializer declared in a class is executed when an instance of the class
is created , as specified in
InstanceInitializer:
Block
An instance initializer declared in a class is executed when an instance of the class
is created , as specified in
InstanceInitializer:
Block
- It is compile-time error if an instance initializer of a named class can throw a
checked exception unless that exception or one of its supertypes is explicitly
declared in the throws clause of each constructor of its class and the class has at
least one explicitly declared constructor. - An instance initializer in an anonymous
class ) can throw any exceptions. - The rules above distinguish between instance initializers in named and anonymous
classes. - This distinction is deliberate. A given anonymous class is only
instantiated at a single point in a program. - It is therefore possible to directly propagate information about what exceptions might be raised by an anonymous class’instance initializer to the surrounding expression.
- Named classes, on the other hand, can be instantiated in many places. Therefore the only way to propagate information about what exceptions might be raised by an instance initializer of a named class is through the throws clauses of its constructors.
0 comments:
Post a Comment