-
Notifications
You must be signed in to change notification settings - Fork 613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Java 17 features #6691
Use Java 17 features #6691
Conversation
Includes features added from 13 through 21 Replace usages of java.util.Optional with our Option type Use switch expressions and new switch syntax where possible Use pattern matching where possible Use enhanced instanceof where possible
Are you handling the case of |
That's not available until Java 21. Switch expressions/statements have historically thrown NPEs until Java 21. And some of the tools say they won't warn on switch expressions because javac will check switch exhaustiveness, but they still warn anyways. |
Apparently switch expressions are separate from arrow labels, so when the linters were warning about missing switch defaults on switch statements, they were, in fact, warning about missing switch defaults on switch statements. Defaults have been put back in, matching whatever previous logic was present. |
Did you do this by hand, or did you use a tool? |
I cherry-picked @SamCarlberg's commit that refactored a bunch of code to use Java 21 features, removed the Java 21 parts to make it Java 17 compatible, and refactored any remaining code, mostly by using VS Code's search feature with the regexes |
int type = 0; | ||
switch (pixelFormat) { | ||
case kYUYV: | ||
case kRGB565: | ||
type = CvType.CV_8UC2; | ||
break; | ||
case kBGR: | ||
type = CvType.CV_8UC3; | ||
break; | ||
case kGray: | ||
case kMJPEG: | ||
default: | ||
type = CvType.CV_8UC1; | ||
break; | ||
} | ||
return type; | ||
return switch (pixelFormat) { | ||
case kYUYV, kRGB565, kY16, kUYVY -> CvType.CV_8UC2; | ||
case kBGR -> CvType.CV_8UC3; | ||
case kBGRA -> CvType.CV_8UC4; | ||
case kGray, kMJPEG, kUnknown -> CvType.CV_8UC1; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting that this is a change in behavior (which matches CvSink
)- I think it's fine, just want to note that down.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I assumed that we want this to match CvSink
.
Uses enhanced instanceof (and simplify
equals
methods)Uses switch expressions and arrow labels
Seal and finalize some Shuffleboard classes