說明
All identifiers must follow standard Java naming conventions:
| Element | Convention | Example |
|---|---|---|
| Package | lowercase, no underscores | com.example.order |
| Class | PascalCase | OrderService |
| Method | camelCase | getOrderById() |
| Field | camelCase | orderRepository |
| Constant | UPPER_SNAKE_CASE | MAX_RETRY_COUNT |
| Parameter | camelCase | orderId |
為什麼重要
Consistent naming reduces cognitive load. A developer should be able to guess the type of an identifier from its name alone.
Enforcement
<module name="TypeName"/>
<module name="MethodName"/>
<module name="ConstantName"/>
<module name="LocalVariableName"/>
<module name="MemberName"/>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="StaticVariableName"/>
正例
public class OrderService {
private static final int MAX_RETRY_COUNT = 3;
public Order getOrderById(Long orderId) {
// ...
}
}
反例
public class order_Service { // ❌ wrong case + underscore
private static final int maxRetry = 3; // ❌ should be UPPER_SNAKE
public Order Get_Order(long order_id) { // ❌ PascalCase method + underscore param
// ...
}
}