mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
49 lines
1.0 KiB
HTML
49 lines
1.0 KiB
HTML
<html>
|
|
<body>
|
|
Reports <code>public</code> constructors.
|
|
<p>Some coding standards discourage the use of <code>public</code> constructors and recommend
|
|
<code>static</code> factory methods instead.
|
|
This way the implementation can be swapped out without affecting the call sites.
|
|
<p><b>Example:</b></p>
|
|
<pre><code>
|
|
class Test {
|
|
private String name;
|
|
|
|
public Test(String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
public void test() {
|
|
System.out.println(name);
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
new Test("str").test();
|
|
}
|
|
}
|
|
</code></pre>
|
|
<p>After quick-fix is applied:</p>
|
|
<pre><code>
|
|
class Test {
|
|
private String name;
|
|
|
|
private Test(String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
public static Test getInstance(String name) {
|
|
return new Test(name);
|
|
}
|
|
|
|
public void test() {
|
|
System.out.println(name);
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
getInstance("str").test();
|
|
}
|
|
}
|
|
</code></pre>
|
|
<!-- tooltip end -->
|
|
</body>
|
|
</html> |