affaan-m/ECC/docs/zh-CN/skills/java-coding-standards/SKILL.md
java-coding-standards
Use it for engineering tasks; the detail page covers purpose, installation, and practical steps.
- Source repository stars
- 234,327
- Declared platforms
- 0
- Static risk flags
- 0
- Last source update
- 2026-07-27
- Source checked
- 2026-07-28
Decision brief
What it does—and where it fits
适用于 Spring Boot 服务中可读、可维护的 Java (17+) 代码的规范。
Not for
- Tasks that require unconfirmed production actions or broad system permissions.
- Environments where the pinned source and install steps cannot be inspected.
Compatibility matrix
Platform support, with evidence labels
| Platform | Status | Evidence | What to check |
|---|---|---|---|
| Codex | Not declared | No explicit evidence | Portability before use |
| Claude Code | Not declared | No explicit evidence | Portability before use |
| Cursor | Not declared | No explicit evidence | Portability before use |
| Gemini CLI | Not declared | No explicit evidence | Portability before use |
Installation
Inspect first. Install second.
The source command is displayed only when detected. A safe inspection prompt is always available so your agent can explain every action before execution.
npx skills add https://github.com/affaan-m/ECC --skill "docs/zh-CN/skills/java-coding-standards"Inspect the Agent Skill "java-coding-standards" from https://github.com/affaan-m/ECC/blob/4e973d3eaf92d97f8d2e2d8abb39d8bdc8711b38/docs/zh-CN/skills/java-coding-standards/SKILL.md at commit 4e973d3eaf92d97f8d2e2d8abb39d8bdc8711b38. List every install step, command, network request, credential, file read/write, external action, and rollback step. Explain whether it fits my task. Do not install or execute anything until I approve.
Workflow
What the source asks the agent to do
- 01
何时激活
在 Spring Boot 项目中编写或审查 Java 代码时 强制执行命名、不可变性或异常处理约定时 使用记录类、密封类或模式匹配(Java 17+)时 审查 Optional、流或泛型的使用时 构建包和项目布局时
在 Spring Boot 项目中编写或审查 Java 代码时强制执行命名、不可变性或异常处理约定时使用记录类、密封类或模式匹配(Java 17+)时 - 02
核心原则
清晰优于巧妙 默认不可变;最小化共享可变状态 快速失败并提供有意义的异常 一致的命名和包结构
清晰优于巧妙默认不可变;最小化共享可变状态快速失败并提供有意义的异常 - 03
命名
Review the “命名” section in the pinned source before continuing.
Review and apply the “命名” source section. - 04
不可变性
Review the “不可变性” section in the pinned source before continuing.
Review and apply the “不可变性” source section.
Permission review
Static risk signals and limitations
No configured static risk pattern was detected
This is not proof of safety. Runtime behavior, indirect dependencies, and hidden external systems are outside the static scan.
Evidence record
Why each signal appears
| Signal | Value | Evidence type | Meaning |
|---|---|---|---|
| Quality score | 72/100 | Computed | Documentation, specificity, maintenance, and trust rules |
| Repository stars | 234,327 | Source | Repository attention, not individual Skill quality |
| Compatibility | 0 platforms | Source | Declared in the catalog source record |
| Usage guide | automated source guide | Editorial | Generated or reviewed according to the visible evidence level |
Pinned source
Provenance and original SKILL.md
- Repository
- affaan-m/ECC
- Skill path
- docs/zh-CN/skills/java-coding-standards/SKILL.md
- Commit
- 4e973d3eaf92d97f8d2e2d8abb39d8bdc8711b38
- License
- MIT
- Collected
- 2026-07-28
- Default branch
- main
View the original SKILL.md
Java 编码规范
适用于 Spring Boot 服务中可读、可维护的 Java (17+) 代码的规范。
何时激活
- 在 Spring Boot 项目中编写或审查 Java 代码时
- 强制执行命名、不可变性或异常处理约定时
- 使用记录类、密封类或模式匹配(Java 17+)时
- 审查 Optional、流或泛型的使用时
- 构建包和项目布局时
核心原则
- 清晰优于巧妙
- 默认不可变;最小化共享可变状态
- 快速失败并提供有意义的异常
- 一致的命名和包结构
命名
// PASS: Classes/Records: PascalCase
public class MarketService {}
public record Money(BigDecimal amount, Currency currency) {}
// PASS: Methods/fields: camelCase
private final MarketRepository marketRepository;
public Market findBySlug(String slug) {}
// PASS: Constants: UPPER_SNAKE_CASE
private static final int MAX_PAGE_SIZE = 100;
不可变性
// PASS: Favor records and final fields
public record MarketDto(Long id, String name, MarketStatus status) {}
public class Market {
private final Long id;
private final String name;
// getters only, no setters
}
Optional 使用
// PASS: Return Optional from find* methods
Optional<Market> market = marketRepository.findBySlug(slug);
// PASS: Map/flatMap instead of get()
return market
.map(MarketResponse::from)
.orElseThrow(() -> new EntityNotFoundException("Market not found"));
Streams 最佳实践
// PASS: Use streams for transformations, keep pipelines short
List<String> names = markets.stream()
.map(Market::name)
.filter(Objects::nonNull)
.toList();
// FAIL: Avoid complex nested streams; prefer loops for clarity
异常
- 领域错误使用非受检异常;包装技术异常时提供上下文
- 创建特定领域的异常(例如,
MarketNotFoundException) - 避免宽泛的
catch (Exception ex),除非在中心位置重新抛出/记录
throw new MarketNotFoundException(slug);
泛型和类型安全
- 避免原始类型;声明泛型参数
- 对于可复用的工具类,优先使用有界泛型
public <T extends Identifiable> Map<Long, T> indexById(Collection<T> items) { ... }
项目结构 (Maven/Gradle)
src/main/java/com/example/app/
config/
controller/
service/
repository/
domain/
dto/
util/
src/main/resources/
application.yml
src/test/java/... (mirrors main)
格式化和风格
- 一致地使用 2 或 4 个空格(项目标准)
- 每个文件一个公共顶级类型
- 保持方法简短且专注;提取辅助方法
- 成员顺序:常量、字段、构造函数、公共方法、受保护方法、私有方法
需要避免的代码坏味道
- 长参数列表 → 使用 DTO/构建器
- 深度嵌套 → 提前返回
- 魔法数字 → 命名常量
- 静态可变状态 → 优先使用依赖注入
- 静默捕获块 → 记录日志并处理或重新抛出
日志记录
private static final Logger log = LoggerFactory.getLogger(MarketService.class);
log.info("fetch_market slug={}", slug);
log.error("failed_fetch_market slug={}", slug, ex);
Null 处理
- 仅在不可避免时接受
@Nullable;否则使用@NonNull - 在输入上使用 Bean 验证(
@NotNull,@NotBlank)
测试期望
- 使用 JUnit 5 + AssertJ 进行流畅的断言
- 使用 Mockito 进行模拟;尽可能避免部分模拟
- 倾向于确定性测试;没有隐藏的休眠
记住:保持代码意图明确、类型安全且可观察。除非证明有必要,否则优先考虑可维护性而非微优化。
Alternatives
Compare before choosing
affaan-m/ECC
java-coding-standards
Java coding standards for Spring Boot and Quarkus services: naming, immutability, Optional usage, streams, exceptions, generics, CDI, reactive patterns, and project layout. Automatically applies framework-specific conventions.
affaan-m/ECC
java-coding-standards
Use it for engineering tasks; the detail page covers purpose, installation, and practical steps.
coreyhaines31/marketingskills
ab-testing
When the user wants to plan, design, or implement an A/B test or experiment, or build a growth experimentation program. Also use when the user mentions "A/B test," "split test," "experiment," "test this change," "variant copy," "multivariate test," "hypothesis," "should I test this," "which version is better," "test two versions," "statistical significance," "how long should I run this test," "growth experiments," "experiment velocity," "experiment backlog," "ICE score," "experimentation program
event4u-app/agent-config
design-intelligence
Grounded design brief from the adopted corpus — style, WCAG-checked color tokens, typography, layout pattern, anti-patterns. Use on ui-design-brief or any which-style/palette/font/chart decision.