mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 15:27:45 +07:00
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
27 lines
1.3 KiB
HTML
27 lines
1.3 KiB
HTML
<html>
|
|
<body>
|
|
Reports <code>clone()</code> methods that do not declare <code>throws CloneNotSupportedException</code>.
|
|
<p>If <code>throws CloneNotSupportedException</code> is not declared, the method's subclasses will not be able to prohibit cloning
|
|
in the standard way. This inspection does not report <code>clone()</code> methods declared <code>final</code>
|
|
and <code>clone()</code> methods on <code>final</code> classes.</p>
|
|
<!-- tooltip end -->
|
|
<p>Configure the inspection:</p>
|
|
<p>Use the <b>Only warn on 'protected' clone methods</b> option to indicate that this inspection should only warn on <code>protected clone()</code> methods.
|
|
The <i>Effective Java</i> book (second and third edition) recommends omitting the <code>CloneNotSupportedException</code>
|
|
declaration on <code>public</code> methods, because the methods that do not throw checked exceptions are easier to use.
|
|
<p>Example:</p>
|
|
<pre><code>
|
|
<b>public class</b> Example <b>implements</b> Cloneable {
|
|
// method doesn't declare 'throws CloneNotSupportedException'
|
|
<b>protected</b> Object clone() {
|
|
<b>try</b> {
|
|
<b>return</b> <b>super</b>.clone();
|
|
} <b>catch</b> (CloneNotSupportedException e) {
|
|
<b>return</b> null;
|
|
}
|
|
}
|
|
}
|
|
</code></pre>
|
|
|
|
</body>
|
|
</html> |