Loading...
Loading...
Generate and review Java code using patterns and best practices from Joshua Bloch's "Effective Java" (3rd Edition). Use this skill whenever the user asks about Java best practices, API design, object creation patterns, generics, enums, lambdas, streams, concurrency, serialization, method design, exception handling, or writing clean, maintainable Java code. Trigger on phrases like "Effective Java", "Java best practices", "builder pattern", "static factory", "defensive copy", "immutable class", "enum type", "generics", "bounded wildcard", "PECS", "stream pipeline", "optional", "thread safety", "serialization proxy", "checked exception", "try-with-resources", "composition over inheritance", "method reference", "functional interface", or "Java API design."
npx skill4agent add booklib-ai/skills effective-javareferences/items-catalog.md| Problem | Items to Apply |
|---|---|
| How to create objects? | Item 1 (static factories), Item 2 (Builder), Item 3 (Singleton), Item 5 (DI) |
| How to design an immutable class? | Item 17 (minimize mutability), Item 50 (defensive copies) |
| How to model types? | Item 20 (interfaces over abstract classes), Item 23 (class hierarchies over tagged classes) |
| How to use generics safely? | Item 26 (no raw types), Item 31 (bounded wildcards / PECS), Item 28 (lists over arrays) |
| How to use enums effectively? | Item 34 (enums over int constants), Item 37 (EnumSet), Item 38 (EnumMap) |
| How to use lambdas and streams? | Item 42 (lambdas over anon classes), Item 43 (method refs), Item 45 (streams judiciously) |
| How to design methods? | Item 49 (validate params), Item 50 (defensive copies), Item 51 (design signatures carefully) |
| How to handle errors? | Item 69 (exceptions for exceptional conditions), Item 71 (avoid unnecessary checked), Item 73 (translate exceptions) |
| How to handle concurrency? | Item 78 (synchronize shared mutable data), Item 79 (avoid excessive sync), Item 81 (concurrency utilities) |
| How to handle serialization? | Item 85 (prefer alternatives), Item 90 (serialization proxies) |
offromvalueOfcreatefinalfinal<? extends T><? super T>List<E>E[]public static final intCollectionStreamObjects.requireNonNull@NullableConcurrentHashMapCountDownLatchwaitnotifyUser: "Create a class to represent a nutritional facts label"
You should generate:
- Immutable class with private final fields (Item 17)
- Builder pattern with fluent API for optional params (Item 2)
- Static factory method NutritionFacts.builder() (Item 1)
- Proper equals, hashCode, toString (Items 10-12)
- Defensive copies for any mutable fields (Item 50)
- @Override annotations (Item 40)User: "Model different payment processing strategies"
You should generate:
- Enum with abstract method and constant-specific implementations (Item 34)
- Strategy pattern via enum (avoiding switch on enum)
- EnumSet for combining payment options (Item 36)
- EnumMap for payment-method-to-processor mapping (Item 37)User: "Build a caching service that handles concurrent access"
You should generate:
- ConcurrentHashMap for thread-safe cache (Item 81)
- Documented thread safety level (Item 82)
- Lazy initialization with double-check idiom if needed (Item 83)
- Composition over inheritance for wrapping underlying store (Item 18)
- Try-with-resources for any closeable resources (Item 9)references/review-checklist.md## Summary
One paragraph: what the code does, which patterns it uses, overall assessment.
## Strengths
What the code does well, which Effective Java items are correctly applied.
## Issues Found
For each issue:
- **What**: describe the problem
- **Why it matters**: explain the bug, maintenance, or performance risk
- **Item to apply**: which Effective Java item addresses this
- **Suggested fix**: concrete code change
## Recommendations
Priority-ordered list of improvements, from most critical to nice-to-have.ListList<String>return nullCollections.emptyList()waitnotifyCountDownLatchCyclicBarrierCompletableFutureDateCalendar+StringBuilderfloatdoubleBigDecimalintlongOptional.get().isPresent()orElseorElseThrowvarreferences/items-catalog.mdreferences/review-checklist.md