This is the same example using a nested record pattern.
[source,java,diff-id=3,diff-type=compliant]
----
void print(Object obj) {
if (obj instanceof Plane(Point(Float x, Float y, Float z), Float d)) { // Compliant
System.out.println(x + y + z);
System.out.println(d);
}
}
----
==== Compliant solution
This example uses `var` instead of replicating the field types in the record pattern, which is less verbose and keeps the code more readable, especially in the case of longer type names.
Also, it uses variable names that do not match the original field names.
The reason for this can be to avoid name collisions with fields or other local variables.
[source,java]
----
void print(Object obj) {
if (obj instanceof Point(var px, var py, var pz)) { // Compliant
System.out.println(px + py + pz);
}
}
----
==== Compliant solution
This example is compliant without using a record pattern, as it does not access all fields.
[source,java]
----
void print(Object obj) {
if (obj instanceof Point p) { // Compliant, because z is never accessed
Float x = p.x;
Float y = p.y();
System.out.println(x + y);
}
}
----
== Resources
* https://openjdk.org/jeps/440[JEP 440: Record Patterns]