[patterns] reconsidering how the created variable name binds

Brian Goetz brian.goetz at oracle.com
Sun Dec 29 19:54:19 UTC 2019



On 12/28/2019 6:20 PM, Remi Forax wrote:
> @Override
> public boolean equals(Object obj) {
>    if (!(obj instanceof Point)) {
>      return false;
>    }
>    Point p = (Point) obj;
>    return x == p.x && y == p.y;
> }
>
> and obviously you want to transform it to:
>
> @Override
> public boolean equals(Object obj) {
>    if (!(obj instanceof Point p)) {
>      return false;
>    }
>    return x == p.x && y == p.y;
> }
>

I would want to transform it further into

@Override
public boolean equals(Object obj) {
   return obj instanceof Point p
      && x == p.x && y == p.y;
}


But your "point" stands, that the above transformation is one people want to do all the time, and would be grumpy if they could not.



More information about the amber-dev mailing list