mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-07 15:35:40 +07:00
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
63 lines
1.8 KiB
HTML
63 lines
1.8 KiB
HTML
<html>
|
|
<body>
|
|
Reports record classes and suggests converting them to ordinary classes.
|
|
<p>This inspection makes it possible to move a Java record to a codebase using an earlier Java version
|
|
by applying the quick-fix to this record.</p>
|
|
<p>
|
|
Note that the resulting class is not completely equivalent to the original record:
|
|
</p>
|
|
<ul>
|
|
<li>The resulting class no longer extends <code>java.lang.Record</code>,
|
|
so <code>instanceof Record</code> returns <code>false</code>.</li>
|
|
<li>Reflection methods like <code>Class.isRecord()</code> and
|
|
<code>Class.getRecordComponents()</code> produce different results.</li>
|
|
<li>The generated <code>hashCode()</code> implementation may produce a different result
|
|
because the formula to calculate record <code>hashCode</code> is deliberately not specified.</li>
|
|
<li>Record serialization mechanism differs from that of an ordinary class.
|
|
Refer to <i>Java Object Serialization Specification</i> for details.</li>
|
|
</ul>
|
|
<!-- tooltip end -->
|
|
<p>Example:</p>
|
|
<pre><code>
|
|
record Point(int x, int y) {}
|
|
</code></pre>
|
|
<p>After the quick-fix is applied:</p>
|
|
<pre><code>
|
|
final class Point {
|
|
private final int x;
|
|
private final int y;
|
|
|
|
Point(int x, int y) {
|
|
this.x = x;
|
|
this.y = y;
|
|
}
|
|
|
|
public int x() { return x; }
|
|
|
|
public int y() { return y; }
|
|
|
|
@Override
|
|
public boolean equals(Object obj) {
|
|
if (obj == this) return true;
|
|
if (obj == null || obj.getClass() != this.getClass()) return false;
|
|
var that = (Point)obj;
|
|
return this.x == that.x &&
|
|
this.y == that.y;
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
return Objects.hash(x, y);
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "Point[" +
|
|
"x=" + x + ", " +
|
|
"y=" + y + ']';
|
|
}
|
|
}
|
|
</code></pre>
|
|
<p><small>New in 2020.3</small></p>
|
|
</body>
|
|
</html> |