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
NewMaintained
Automatic
◆Coding pack
Last verified 8/20/2026
What it changes
Passed 0 of 22 test cases with the skill, and 22 of 22 without it.
Without skill100%
With skill0%
Checks it passed that the model alone missed
Executes `./mvnw compile` before making modifications.
Executes `./mvnw clean verify` for project verification.
2 fixed18 passed either way4 still failing1 broke
Pass-rate lift
-100 pp
Tokens
+15%
Agent turns
0%
Response time
-25%
Model gemini-3.6-flashMeasured 8/20/2026v120 of 25 cases passed with skill · 22 comparable
Tokens, turns and time describe resource use, not a dollar price.
See it in action
One of 2 test cases the skill fixed. Same model, same prompt, with and without the skill.
1 of 2
Prompt
After successfully refactoring raw types in a Java repository and ensuring compilation succeeds, what Maven command must be executed to complete final build verification?
What was checked, without and with the skill
Checked
Without skill
With skill
Executes `./mvnw clean verify` for project verification.
Missed
Passed
case-15 · gemini-3.6-flash · 8/20/2026 · answers are capped and redacted
What's inside
The instructions your model reads when the skill loads.
SKILL.md61 lines2 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
Scope: The reference is organized by examples (good/bad code patterns) for each core area. Apply recommendations based on applicable examples.
Constraints
Before applying any generics changes, ensure the project compiles. If compilation fails, stop immediately — do not proceed until resolved. After applying improvements, run full verification.
MANDATORY: Run ./mvnw compile or mvn compile before applying any change
SAFETY: If compilation fails, stop immediately and do not proceed — compilation failure is a blocking condition
VERIFY: Run ./mvnw clean verify or mvn clean verify after applying improvements
BEFORE APPLYING: Read the reference for detailed examples, good/bad patterns, and constraints
EDGE CASE: If request scope is ambiguous, stop and ask a clarifying question before applying changes
EDGE CASE: If required inputs, files, or tooling are missing, report what is missing and ask whether to proceed with setup guidance
Use when you need to set up, review, or improve Java integration tests — including generating a BaseIntegrationTest.java with WireMock for HTTP stubs, detecting HTTP client infrastructure from import signals, injecting service coordinates dynamically via System.setProperty(), creating WireMock JSON mapping files with bodyFileName, isolating stubs per test method, verifying HTTP interactions, or eliminating anti-patterns such as Mockito-mocked HTTP clients or globally registered WireMock stubs. T