In Java, it is possible to declare multiple variables of the same type on a single line using commas. This can make code more cluttered and less readable. Declare each variable on a separate line to improve code clarity and maintainability.
Non-Compliant Code Examples
publicclassPerson{// combined declarations (same line) - a violationStringfirstName,lastName;// combined declaration (diff line) - no violationStringfirstName,lastName;}
Compliant Code Examples
publicclassPerson{// separate declarations - no violationStringfirstName;StringlastName;}
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