jabrena avatar

128 Java Generics

This is a comprehensive refactoring assistant for cleaning up Java generics across your codebase. It walks you through eliminating raw types, applying PECS (Producer Extends Consumer Super) for wildcards, fixing unsafe casts, and integrating generics with modern Java features like Records and sealed types. The workflow is strict: it forces a compile check before touching anything, then guides you through the reference material with good/bad code examples, then verifies everything still builds. Honestly, the mandatory compile gates are smart because generics refactoring can spiral into type errors fast. Best used when you have legacy code that compiles but is littered with warnings, or when you're tightening up API boundaries and want proper variance.

skills.sh installs
135
GitHub stars
393
last updated
Jun 3, 2026

Install

$ npx -y skills add jabrena/cursor-rules-java --skill 128-java-generics --agent claude-code

Installs into .claude/skills of the current project.

Files

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 (CRTP) for fluent builders
  • Proper wildcard API design: Comparator<? super T>, Function<? super T, ? extends R>
  • Arrays-vs-generics covariance pitfalls, serialization with TypeReference/TypeToken
  • Generic naming conventions (T, E, K/V, ?), typesafe heterogeneous containers
  • Integration with Records, sealed types, and pattern matching

Sponsors

Details

Repository
github.com/jabrena/cursor-rules-java
Category
Java & JVM
First seen
Jun 3, 2026

More from jabrena/cursor-rules-java

All 16

Recommended

More Java & JVM
1jabrena avatar141-java-refactoring-with-modern-featuresjabrena/cursor-rules-java141 java refactoring with modern features135skills.sh installs
2jabrena avatar131-java-testing-unit-testingjabrena/cursor-rules-java131 java testing unit testing134skills.sh installs
3jabrena avatar143-java-functional-exception-handlingjabrena/cursor-rules-java143 java functional exception handling133skills.sh installs
4jabrena avatar122-java-type-designjabrena/cursor-rules-java122 java type design132skills.sh installs
5jabrena avatar132-java-testing-integration-testingjabrena/cursor-rules-java132 java testing integration testing128skills.sh installs
6teachingai avatarspring-cloud-alibabateachingai/full-stack-skillsspring cloud alibaba120skills.sh installs