Files
openide/java/java-impl/resources/inspectionDescriptions/PublicConstructor.html
Leonid Shalupov 40795fe787 IJI-2422: community/java: move resources under resources root
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
2025-02-05 04:43:28 +00:00

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>