-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Open
Description
In generated Parser code, explicit casts are used, when pattern matching has been available since JDK16: https://openjdk.org/jeps/394
For example:
@Override
public void enterRule(ParseTreeListener listener) {
if (listener instanceof MyListener) ((MyListener) listener).enterSomeRule(this);
}
could be changed to
@Override
public void enterRule(ParseTreeListener listener) {
if (listener instanceof MyListener listener1) listener.enterSomeRule(this);
}
to avoid the extra downcast.
This would definitely require testing to determine if this is actually a performance benefit, but if it's a wash, it seems reasonable to avoid extra casting when you are already checking the type via instanceof
.
If nothing else, it simplifies the generated code slightly!
eljonny
Metadata
Metadata
Assignees
Labels
No labels