Deconstructor return type as record ?
Remi Forax
forax at univ-mlv.fr
Thu Jan 2 21:08:47 UTC 2020
We have introduce records because it's a simple abstraction to extract values when doing the pattern matching.
Given that records are named tuples, does it means that a deconstructor is just a classical method with no parameter and a record as return type ?
public class Point {
private final double rho, theta;
public Point(double x, double y) {
rho = Math.hypot(x, y);
teta = Math.atan(y / x);
}
public record RectangularPoint(double x, double y) { }
public RectangularPoint deconstructor() {
return new RectangularPoint(rho * Math.cos(theta), rho * sin(theta));
}
}
and with a little syntactic sugar to see any tuples as a Record (like we see any lambdas as a functional interface)
public RectangularPoint deconstructor() {
return (rho * Math.cos(theta), rho * sin(theta));
}
Rémi
More information about the amber-spec-experts
mailing list