Files
2025-09-05 18:05:54 +00:00

54 lines
1.8 KiB
HTML

<html>
<body>
Reports classes that can be converted to record classes.
<p>Record classes focus on modeling immutable data rather than extensible behavior.
Automatic implicit implementation of data-driven methods, such as <code>equals()</code> and accessors, helps to reduce boilerplate code.</p>
<p>
Note that not every class can be a record class. Here are some restrictions:
</p>
<ul>
<li>The class must have no subclasses.</li>
<li>All non-static fields in the class must be final.</li>
<li>Initializers, generic constructors, and native methods must not be present.</li>
</ul>
<p>For a full description of record classes, refer to the
<a href="https://docs.oracle.com/javase/specs/jls/se21/html/jls-8.html#jls-8.10">Java Language Specification</a>.</p>
<!-- tooltip end -->
<p>Example:</p>
<pre><code>
class Point {
private final double x;
private final double y;
Point(double x, double y) {
this.x = x;
this.y = y;
}
double getX() {
return x;
}
double getY() {
return y;
}
}
</code></pre>
<p>After the quick-fix is applied:</p>
<pre><code>
record Point(int x, int y) {
}
</code></pre>
<p>Enable the <b>Suggest renaming accessor methods</b> option to rename <code>getX()</code>/<code>isX()</code> accessors to <code>x()</code> automatically.</p>
<p>
Use the <b>Don't report if members become more accessible</b> option to exclude classes whose members'
accessibility would be weakened by conversion.
Quick-fix will stay available as an intention, and triggering it will show the affected members and ask for confirmation.
In batch mode conversion will not be suggested.
</p>
<p>Use the <b>Suppress conversion if the class is annotated by</b> list to exclude classes from conversion when annotated by annotations matching the specified patterns.
</p>
<p><small>New in 2020.3</small></p>
</body>
</html>