Σε εγγραφές μπορούμε να ταιριάξουμε και τα ορίσματά τους.
class PaternMatch {
record Point2D(double x,double y) {}
record Point3D(double x,double y,double z) {}/** Output the magnitude of the specified object */private static voidprintMagnitude(Object o) {
System.out.println("Magnitude of "+ o +" is "+switch(o) {casePoint2D(double x,double y) -> Math.sqrt(x * x + y * y);casePoint3D(double x,double y,double z) ->
Math.sqrt(x * x + y * y + z * z);default->throw newIllegalArgumentException("Unexpected type: "+ o.getClass().getName());});}public static voidmain(String[] args) {printMagnitude(newPoint2D(3,4));// Pythagorean tripleprintMagnitude(newPoint3D(1,4,8));// Pythagorean quadruple}}