Skip to content

Commit 7094ddd

Browse files
committed
config: add static import convention for common constants like UTF_8
1 parent 0a0c9f3 commit 7094ddd

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

.claude/rules/java.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ try (java.util.stream.Stream<Path> walk = Files.walk(dir))
5151

5252
**Exception:** FQNs are acceptable in Javadoc `{@link}` / `{@code}` tags when the type is not already imported.
5353

54+
### Static Imports for Common Constants
55+
56+
Use static imports for frequently used constants to reduce verbosity:
57+
58+
```java
59+
// Good - static import
60+
import static java.nio.charset.StandardCharsets.UTF_8;
61+
62+
byte[] bytes = str.getBytes(UTF_8);
63+
64+
// Avoid - qualified constant
65+
byte[] bytes = str.getBytes(StandardCharsets.UTF_8);
66+
```
67+
5468
### Single-Statement Blocks
5569
Omit braces for if/else/for/while with a single-statement body that fits on one visual line.
5670
Add braces when the body spans multiple visual lines (e.g., string concatenation continuation):

0 commit comments

Comments
 (0)