Forums Register Login

Instance Initializer, throw statement

+Pie Number of slices to send: Send
The JLS section 8.6 :

An instance initializer of a named class may not throw a checked exception unless
that exception or one of its superclasses 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 (�15.9.5) can throw any exceptions.



According to the statement the following code should compile, but it is not compiling.

Pease clear my doubt..
regards
-Manish
+Pie Number of slices to send: Send
You are right. The code should compile according to JSL. This a point where the compiler doesn't conform to the JLS. There is a bug report in Sun's database, and I think, it has been also commented here in the Ranch.
+Pie Number of slices to send: Send
Thanx Jose,
But should I expect this type of question in the exam?
+Pie Number of slices to send: Send
Not at all. They are careful enough in order not to show the possible bugs or inconsitencies of the compiler.
You can thank my dental hygienist for my untimely aliveness. So tiny:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 710 times.
Similar Threads
a question about super command
What is an Instance Initializer?
Exception and Instance Initializer
Exception in instance initializer !!!!!!!
Initializer doubt
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:10:44.