src/main/resources/skills/java-best-practices/SKILL.md
Java 编码最佳实践与设计模式
npx skillsauth add leavesfly/jimi java-best-practicesInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
单例模式(枚举实现):
public enum Singleton {
INSTANCE;
public void doSomething() {}
}
工厂模式:
public class UserFactory {
public static User createUser(String type) {
return switch (type) {
case "admin" -> new AdminUser();
case "guest" -> new GuestUser();
default -> new RegularUser();
};
}
}
Builder 模式:
User user = User.builder()
.name("张三")
.age(25)
.build();
List<String> names = users.stream()
.filter(u -> u.getAge() > 18)
.map(User::getName)
.collect(Collectors.toList());
try {
// 业务逻辑
} catch (SpecificException e) {
log.error("Error: {}", e.getMessage(), e);
throw new BusinessException("操作失败");
} finally {
// 清理资源
}
ExecutorService executor = Executors.newFixedThreadPool(10);
executor.submit(() -> {
// 异步任务
});
Optional<User> user = userRepository.findById(id);
return user.orElseThrow(() -> new NotFoundException());
testing
示例技能,用于 PluginRegistry 测试
development
Get current weather and forecasts (no API key required).
testing
Java单元测试编写指南(基于JUnit和Mockito)
documentation
Git 提交规范(Conventional Commits)