{"id":"7fb88f4f-e2d0-4a26-b9ca-bbc87ed8bbd9","shortId":"LvtDwA","kind":"skill","title":"128-java-generics","tagline":"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","description":"# Java Generics Best Practices\n\nReview and improve Java code using comprehensive generics best practices that enforce compile-time type safety and enable flexible, reusable APIs.\n\n**What is covered in this Skill?**\n\n- Type safety: avoiding raw types, eliminating unsafe casts\n- Code reusability: generic methods and types for multiple type contexts\n- PECS wildcards: `? extends` for producers, `? super` for consumers\n- Diamond operator for type inference\n- Type erasure awareness: type tokens, factory patterns, array creation\n- Generic inheritance and variance: invariance, covariance, contravariance\n- `@SafeVarargs` for heap pollution prevention\n- Wildcard capture helpers, self-bounded generics (CRTP) for fluent builders\n- Proper wildcard API design: `Comparator<? super T>`, `Function<? super T, ? extends R>`\n- Arrays-vs-generics covariance pitfalls, serialization with `TypeReference`/`TypeToken`\n- Generic naming conventions (`T`, `E`, `K/V`, `?`), typesafe heterogeneous containers\n- Integration with Records, sealed types, and pattern matching\n\n**Scope:** The reference is organized by examples (good/bad code patterns) for each core area. Apply recommendations based on applicable examples.\n\n## Constraints\n\nBefore applying any generics changes, ensure the project compiles. If compilation fails, stop immediately — do not proceed until resolved. After applying improvements, run full verification.\n\n- **MANDATORY**: Run `./mvnw compile` or `mvn compile` before applying any change\n- **SAFETY**: If compilation fails, stop immediately and do not proceed — compilation failure is a blocking condition\n- **VERIFY**: Run `./mvnw clean verify` or `mvn clean verify` after applying improvements\n- **BEFORE APPLYING**: Read the reference for detailed examples, good/bad patterns, and constraints\n- **EDGE CASE**: If request scope is ambiguous, stop and ask a clarifying question before applying changes\n- **EDGE CASE**: If required inputs, files, or tooling are missing, report what is missing and ask whether to proceed with setup guidance\n\n## When to use this skill\n\n- Improve the code with Generics\n- Apply Generics\n- Refactor the code with Generics\n\n## Workflow\n\n1. **Compile project before generics changes**\n\nRun `./mvnw compile` or `mvn compile` and stop immediately if compilation fails.\n\n2. **Read generics reference and assess type safety**\n\nRead `references/128-java-generics.md` and identify raw types, unsafe casts, wildcard misuse, and API variance opportunities.\n\n3. **Apply generics refactorings**\n\nImplement selected generic type and API improvements while preserving behavior.\n\n4. **Verify with full build**\n\nRun `./mvnw clean verify` or `mvn clean verify` after applying improvements.\n\n## Reference\n\nFor detailed guidance, examples, and constraints, see [references/128-java-generics.md](references/128-java-generics.md).","tags":["128","java","generics","cursor","rules","jabrena","agent-skills","ai-skills","claude","claude-code","claude-code-skills","claude-code-subagents"],"capabilities":["skill","source-jabrena","skill-128-java-generics","topic-agent-skills","topic-ai-skills","topic-claude","topic-claude-code","topic-claude-code-skills","topic-claude-code-subagents","topic-claude-skills","topic-cursor-agent","topic-cursor-ai","topic-cursor-skills","topic-cursorai","topic-github-copilot"],"categories":["cursor-rules-java"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/jabrena/cursor-rules-java/128-java-generics","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"cli":"npx skills add jabrena/cursor-rules-java","source_repo":"https://github.com/jabrena/cursor-rules-java","install_from":"skills.sh"}},"qualityScore":"0.631","qualityRationale":"deterministic score 0.63 from registry signals: · indexed on github topic:agent-skills · 362 github stars · SKILL.md body (2,847 chars)","verified":false,"liveness":"unknown","lastLivenessCheck":null,"agentReviews":{"count":0,"score_avg":null,"cost_usd_avg":null,"success_rate":null,"latency_p50_ms":null,"narrative_summary":null,"summary_updated_at":null},"enrichmentModel":"deterministic:skill-github:v1","enrichmentVersion":1,"enrichedAt":"2026-04-26T18:53:41.170Z","embedding":null,"createdAt":"2026-04-18T22:01:58.731Z","updatedAt":"2026-04-26T18:53:41.170Z","lastSeenAt":"2026-04-26T18:53:41.170Z","tsv":"'/mvnw':226,253,338,391 '1':331 '128':1 '2':349 '3':371 '4':385 'ambigu':281 'api':69,141,368,380 'appli':23,192,200,219,232,261,264,289,323,372,399 'applic':196 'area':191 'array':114,152 'arrays-vs-gener':151 'ask':284,306 'assess':354 'avoid':20,78 'awar':109 'base':194 'behavior':384 'best':46,56 'block':249 'bound':34,133 'build':389 'builder':138 'captur':129 'case':276,292 'cast':83,364 'chang':203,234,290,336 'clarifi':286 'clean':254,258,392,396 'code':15,52,84,186,320,327 'compar':143 'compil':61,207,209,227,230,237,245,332,339,342,347 'compile-tim':60 'comprehens':54 'condit':250 'constraint':198,274,407 'consum':28,101 'contain':169 'context':93 'contravari':122 'convent':163 'core':190 'covari':121,155 'cover':72 'creation':115 'crtp':135 'design':37,142 'detail':269,403 'diamond':43,102 'e':165 'edg':275,291 'effect':38 'elimin':81 'enabl':66 'enforc':59 'ensur':204 'erasur':108 'exampl':184,197,270,405 'extend':27,96,149 'factori':112 'fail':210,238,348 'failur':246 'file':296 'flexibl':67 'fluent':137 'full':222,388 'function':146 'generic':4,17,39,45,55,86,116,134,154,161,202,322,324,329,335,351,373,377 'good/bad':185,271 'guidanc':312,404 'heap':125 'helper':130 'heterogen':168 'identifi':360 'immedi':212,240,345 'implement':375 'improv':11,50,220,262,318,381,400 'includ':19 'infer':106 'inherit':117 'input':295 'integr':170 'invari':120 'java':3,14,44,51 'java-gener':2 'k/v':166 'leverag':41 'mandatori':224 'match':177 'method':40,87 'miss':300,304 'misus':366 'multipl':91 'mvn':229,257,341,395 'name':162 'need':8 'oper':103 'opportun':370 'organ':182 'paramet':36 'pattern':113,176,187,272 'pec':25,94 'pitfal':156 'pollut':126 'practic':47,57 'preserv':383 'prevent':127 'principl':30 'proceed':215,244,309 'produc':26,98 'project':206,333 'proper':139 'qualiti':18 'question':287 'r':150 'raw':21,79,361 'read':265,350,357 'recommend':193 'record':172 'refactor':13,325,374 'refer':180,267,352,401 'references/128-java-generics.md':358,409,410 'report':301 'request':278 'requir':294 'resolv':217 'reusabl':68,85 'review':10,48 'run':221,225,252,337,390 'safeti':64,77,235,356 'safevararg':123 'scope':178,279 'seal':173 'see':408 'select':376 'self':132 'self-bound':131 'serial':157 'setup':311 'skill':75,317 'skill-128-java-generics' 'source-jabrena' 'stop':211,239,282,344 'super':29,99,144,147 'time':62 'token':111 'tool':298 'topic-agent-skills' 'topic-ai-skills' 'topic-claude' 'topic-claude-code' 'topic-claude-code-skills' 'topic-claude-code-subagents' 'topic-claude-skills' 'topic-cursor-agent' 'topic-cursor-ai' 'topic-cursor-skills' 'topic-cursorai' 'topic-github-copilot' 'type':22,35,63,76,80,89,92,105,107,110,174,355,362,378 'typerefer':159 'typesaf':167 'typetoken':160 'unsaf':82,363 'use':5,33,53,315 'varianc':119,369 'verif':223 'verifi':251,255,259,386,393,397 'vs':153 'whether':307 'wildcard':32,95,128,140,365 'workflow':330","prices":[{"id":"4af3e728-0c3d-4101-8d7c-2b653a58f40d","listingId":"7fb88f4f-e2d0-4a26-b9ca-bbc87ed8bbd9","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"jabrena","category":"cursor-rules-java","install_from":"skills.sh"},"createdAt":"2026-04-18T22:01:58.731Z"}],"sources":[{"listingId":"7fb88f4f-e2d0-4a26-b9ca-bbc87ed8bbd9","source":"github","sourceId":"jabrena/cursor-rules-java/128-java-generics","sourceUrl":"https://github.com/jabrena/cursor-rules-java/tree/main/skills/128-java-generics","isPrimary":false,"firstSeenAt":"2026-04-18T22:01:58.731Z","lastSeenAt":"2026-04-26T18:53:41.170Z"}],"details":{"listingId":"7fb88f4f-e2d0-4a26-b9ca-bbc87ed8bbd9","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"jabrena","slug":"128-java-generics","github":{"repo":"jabrena/cursor-rules-java","stars":362,"topics":["agent-skills","ai-skills","claude","claude-code","claude-code-skills","claude-code-subagents","claude-skills","cursor-agent","cursor-ai","cursor-skills","cursorai","github-copilot","intellij-idea","java","prompting","system-prompts"],"license":"apache-2.0","html_url":"https://github.com/jabrena/cursor-rules-java","pushed_at":"2026-04-26T13:48:39Z","description":"A curated and opinionated collection of Skills and Agents to be used in modern SDLC workflows for Java Enterprise development with your favorite AI Agent harness.","skill_md_sha":"b29a059d9f2c26ca3b51a1005d560ed4ab4c55b7","skill_md_path":"skills/128-java-generics/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/jabrena/cursor-rules-java/tree/main/skills/128-java-generics"},"layout":"multi","source":"github","category":"cursor-rules-java","frontmatter":{"name":"128-java-generics","license":"Apache-2.0","description":"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. Part of cursor-rules-java project"},"skills_sh_url":"https://skills.sh/jabrena/cursor-rules-java/128-java-generics"},"updatedAt":"2026-04-26T18:53:41.170Z"}}