Understanding javac generated code for record patterns #1991
Closed
srikanth-sankaran
started this conversation in
General
Replies: 1 comment 1 reply
-
@stephan-herrmann , @jarthana @mpalat @iloveeclipse - what am I overlooking ?? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!
Given this program:
javac from JDK21 seems to generate the following code for the method
print
:This looks sub-optimal as well a bit irregular to me.
10: invokevirtual #9 // Method Rectangle.upperLeft:()LColoredPoint;
, why would we at bci 17 do17: instanceof #13 // class ColoredPoint
- isn't this redundant ?? If the record class underwent any incompatible changes, the accessor invocation would have thrown an exception and if it finished normally the stack will have a ColoredPoint - why would I have to check it again withinstanceof
?27: invokevirtual #15 // Method Rectangle.lowerRight:()LColoredPoint;
does not have aninstanceof
check - what would explain this ?Beta Was this translation helpful? Give feedback.
All reactions