Re:Java 21: What’s New?
by morepork on Wednesday August 09, 2023 @07:16PM
(#37069694)
It's a bit of an unkind example as most would write the latter as
if (obj instanceof Point p) {
System.out.println(p.x()+p.y());
}
But I can maybe see the value if you need to use x/y more than once.
However in Java it's common to have getX() style accessors, for which this syntax doesn't seem that helpful as your variable would end up being called getX
However in Java it's common to have getX() style accessors, for which this syntax doesn't seem that helpful as your variable would end up being called getX