128-java-generics
面向泛型正确性与 API 可复用性的实用规则集合
审查与改进 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
帮我安装这个 skill:https://raw.githubusercontent.com/jabrena/plinth/main/skills/128-java-generics/SKILL.mdcurl -fsSL "https://raw.githubusercontent.com/jabrena/plinth/main/skills/128-java-generics/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