classFoo{publicStringgetValue(intnum){switch(num){case1:return"One";case2:return"Two";case3:return"Three";}}publicStringgetValue2(MyTypenum){switch(num){case1:return"One";case2:return"Two";case3:return"Three";}}}classBar{publicStringgetValue(intnum){if(something){switch(num){case1:// a commentreturn"One";case2:return"Two";// another commentcase3:return"Three";}}else{if(somethingElse){switch(num){case'j':// a commentreturn"One";case2.3:return"Two";// another commentcase3:return"Three";}}}}}
Compliant Code Examples
classFoo{publicStringgetValue(intnum){switch(num){case1:return"One";case2:return"Two";case3:return"Three";default:return"Unknown"}}}classBar{publicStringgetValue(intnum){switch(num){case1:// a commentreturn"One";case2:return"Two";// another commentcase3:return"Three";default:return"Unknown"}}}classBar{publicStringgetValue(intnum){returnswitch(num){case1->"one";case2->"two";default->"unknown";}}}
Seamless integrations. Try Datadog Code Analysis
Datadog Code Analysis
Try this rule and analyze your code with Datadog Code Analysis
How to use this rule
1
2
rulesets:- java-best-practices # Rules to enforce Java best practices.
Create a static-analysis.datadog.yml with the content above at the root of your repository
Use our free IDE Plugins or add Code Analysis scans to your CI pipelines