mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
54 lines
2.0 KiB
HTML
54 lines
2.0 KiB
HTML
<html>
|
|
<body>
|
|
Reports classes that can be converted 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 of the 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>If members become more accessible</b> option to specify what to do when conversion will make members more accessible:
|
|
<ul>
|
|
<li>Choose <b>Do not suggest conversion</b> option to not convert when members would become more accessible.</li>
|
|
<li>Choose <b>Show conflicts view</b> option to show the affected members and ask to continue. In batch mode conversion will not be suggested.</li>
|
|
<li>Choose <b>Convert silently</b> option to increase accessibility silently when needed.</li>
|
|
</ul>
|
|
<p>Use the <b>Suppress conversion if 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> |