| Author |
clone() method
|
Harwinder Bhatia
Ranch Hand
Joined: Oct 17, 2003
Posts: 150
|
|
In the following example, why isn't the constructor required to declare CloneNotSupportedException in its 'throws' clause: This program compiles and runs without any problem. CloneNotSupportedException is derived from Exception, which makes it a checked exception. Thanks Harwinder
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
When a class implements a method, it is allowed to narrow the exception specification -- it's perfectly acceptable for an implementation of clone() to declare that it throws no exceptions. I don't recall the JLS stating explicitly that the implementations of clone() in the array classes had empty exception specifications -- but if you think about it, it makes obvious sense.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Harwinder Bhatia
Ranch Hand
Joined: Oct 17, 2003
Posts: 150
|
|
Yes Ernest, it does make sense if the implementation of array classes do not throw this exception. Well, thanks for your response. Regards Harwinder
|
 |
Harwinder Bhatia
Ranch Hand
Joined: Oct 17, 2003
Posts: 150
|
|
Ernest I found supporting evidence for what you said. This is an excerpt from the JLS:
10.7 Array Members The members of an array type are all of the following: 1. The public final field length, which contains the number of components of the array (length may be positive or zero) 2. The public method clone, which overrides the method of the same name in class Object and throws no checked exceptions 3. All the members inherited from class Object; the only method of Object that is not inherited is its clone method
Thanks Harwinder
|
 |
 |
|
|
subject: clone() method
|
|
|