Prompt
Follow Spring Framework’s code style guidelines to ensure consistency across the codebase. Key rules include:
- Import statements:
- Use specific imports rather than wildcard imports
- Maintain consistent import ordering
- Avoid static imports except in specific cases
- Field and variable references:
- Always prefix instance field references with
this. - Don’t declare local variables as
finalunless there’s a compelling reason - Don’t use
varin production code
- Always prefix instance field references with
- Formatting:
- Use tabs for indentation, not spaces
- Remove unnecessary spaces inside parentheses
- Aim for 90 characters per line (maximum 120), with 80 for Javadoc
- Place opening braces on the same line,
elsestatements on a new line
- Before submitting:
- Run
./gradlew checkto catch style violations automatically
- Run
Example of proper style:
public class MyClass {
private final String field;
public MyClass(String parameter) {
this.field = parameter;
}
public void doSomething(String input) {
if (input == null) {
return;
}
else {
String result = processInput(this.field, input);
processResult(result);
}
}
}