mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
46 lines
1.3 KiB
HTML
46 lines
1.3 KiB
HTML
<html>
|
|
<body>
|
|
Reports fields that can be safely made <code>final</code>.
|
|
All <code>final</code> fields have a value and this value does not change, which can make the code easier to reason about.
|
|
<p>To avoid too expensive analysis, this inspection only reports if the field has a <code>private</code> modifier
|
|
or it is defined in a local or anonymous class.
|
|
A field can be <code>final</code> if:
|
|
<ul>
|
|
<li>It is <code>static</code> and initialized once in its declaration or in one <code>static</code> initializer.</li>
|
|
<li>It is non-<code>static</code> and initialized once in its declaration, in one instance initializer or in every constructor</li>
|
|
</ul>
|
|
And it is not modified anywhere else.
|
|
<p><b>Example:</b></p>
|
|
<pre><code>
|
|
public class Person {
|
|
private String name; // can be final
|
|
|
|
Person(String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
}
|
|
</code></pre>
|
|
<p>After the quick-fix is applied:</p>
|
|
<pre><code>
|
|
public class Person {
|
|
private final String name;
|
|
|
|
Person(String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
}
|
|
</code></pre>
|
|
<!-- tooltip end -->
|
|
<p>
|
|
Use the "Annotations" button to modify the list of annotations that assume implicit field write.
|
|
</p>
|
|
</body>
|
|
</html> |