128-java-generics

Refactor Java source code to replace raw types with parameterized generics.

Updated Jul 6, 2026
One-click install
npx skills add https://github.com/shirulot/codex-skill --skill 128-java-generics-shirulot
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: 128-java-generics
Source: https://github.com/shirulot/codex-skill/tree/main/128-java-generics
Command: npx skills add https://github.com/shirulot/codex-skill --skill 128-java-generics-shirulot

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This skill addresses the complexity of Java generics, helping developers eliminate runtime ClassCastException errors, reduce code duplication, and enforce strict compile-time type safety.

Core Features & Use Cases

  • Type Safety Enforcement: Identifies and replaces dangerous raw types with parameterized types to ensure robust code.
  • PECS Principle Application: Guides the correct use of Producer Extends and Consumer Super wildcards to maximize API flexibility.
  • Modern Integration: Provides patterns for combining generics with Records, sealed types, and pattern matching.
  • Use Case: Refactor a legacy collection utility class to use bounded type parameters and proper wildcards, ensuring it works seamlessly with both specific types and their subtypes.

Quick Start

Apply the 128-java-generics skill to refactor the current project code for improved type safety and generic best practices.

Frequently Asked Questions about 128-java-generics

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I eliminate raw types in Java to enforce compile-time type safety?

To enforce compile-time type safety, you must eliminate raw types by refactoring Java source code to use parameterized types. This process replaces dangerous untyped collections with bounded type parameters, ensuring robust code and reducing runtime ClassCastException errors.

When should I apply the PECS principle with wildcards in Java generics?

Apply the PECS principle—Producer Extends, Consumer Super—when designing generic APIs to maximize flexibility. Use extends wildcards for producers and super wildcards for consumers to ensure your generic utility classes accept both specific types and their subtypes seamlessly.

What is the best way to refactor a legacy collection utility class for generic type parameters?

The best way to refactor a legacy collection utility class is to apply bounded type parameters and proper wildcards. This refactoring eliminates unnecessary casting, enforces strict compile-time type checking, and ensures the utility integrates seamlessly with specific types and their subtypes.

Can I combine Java generics with modern features like Records and sealed types?

Yes, you can combine Java generics with modern features. Refactoring patterns provide specific integration methods for combining generics with Records, sealed types, and pattern matching to improve API flexibility and maintain strict type safety in modern Java projects.

Why does my Java generic code still throw ClassCastException at runtime?

Java generic code throws ClassCastException at runtime when raw types bypass compile-time type checking. Refactoring your code to implement type-safe generic patterns and enforce strict compile-time type safety eliminates these runtime errors and ensures robust code execution.