128-java-generics

仓库创建 2025年2月9日最近提交 3 天前SkillHot 收录 21 天前
▸ 精选理由

面向泛型正确性与 API 可复用性的实用规则集合

这个 Skill 做什么

审查与改进 Java 泛型代码,提升类型安全与复用性

审查并改进 Java 里的泛型用法,让编译期类型检查更严格、代码更可复用。常在要消除 raw type、不安全强转,或设计泛型方法、使用边界类型参数和 PECS 通配符时用到。它会关注 type erasure 的影响、@SafeVarargs 和 heap pollution 的防护,也能把泛型和 Records、sealed 类型、pattern matching 等现代特性配合起来。

▸ 展开 SKILL.md 英文原文

Use when you need to review, improve, or refactor Java code for generics quality — including avoiding raw types, applying the PECS (Producer Extends Consumer Super) principle for wildcards, using bounded type parameters, designing effective generic methods, leveraging the diamond operator, understanding type erasure implications, handling generic inheritance correctly, preventing heap pollution with @SafeVarargs, and integrating generics with modern Java features like Records, sealed types, and pattern matching. This should trigger for requests such as Improve the code with Generics; Apply Generics; Refactor the code with Generics; Improve generic type safety in Java APIs; Fix raw types and unchecked casts in Java code. Part of Plinth Toolkit

开发编程Java泛型类型安全通用
423
Stars
89
Forks
40
仓库内 Skill
+9
7 日增星
安装 / 使用
给你的 Agent 一句话(通用)
帮我安装这个 skill:https://raw.githubusercontent.com/jabrena/plinth/main/skills/128-java-generics/SKILL.md
或 curl 直取 SKILL.md
curl -fsSL "https://raw.githubusercontent.com/jabrena/plinth/main/skills/128-java-generics/SKILL.md"
SKILL.MD 节选查看完整文件 ↗
# Java Generics Best Practices

Review and improve Java code using comprehensive generics best practices that enforce compile-time type safety and enable flexible, reusable APIs.

**What is covered in this Skill?**

- Type safety: avoiding raw types, eliminating unsafe casts
- Code reusability: generic methods and types for multiple type contexts
- PECS wildcards: `? extends` for producers, `? super` for consumers
- Diamond operator for type inference
- Type erasure awareness: type tokens, factory patterns, array creation
- Generic inheritance and variance: invariance, covariance, contravariance
- `@SafeVarargs` for heap pollution prevention
- Wildcard capture helpers, self-bounded generics 
via SKILL·HOT · 数据来自 GitHub 公开信息 · 原文版权归作者所有