Java
// Write robust Java avoiding null traps, equality bugs, and concurrency pitfalls.
$ git log --oneline --stat
stars:1,933
forks:367
updated:March 4, 2026
SKILL.mdreadonly
SKILL.md Frontmatter
nameJava
slugjava
version1.0.1
descriptionWrite robust Java avoiding null traps, equality bugs, and concurrency pitfalls.
metadata[object Object]
Quick Reference
| Topic | File |
|---|---|
| Nulls, Optional, autoboxing | nulls.md |
| Collections and iteration traps | collections.md |
| Generics and type erasure | generics.md |
| Concurrency and synchronization | concurrency.md |
| Classes, inheritance, memory | classes.md |
| Streams and CompletableFuture | streams.md |
| Testing (JUnit, Mockito) | testing.md |
| JVM, GC, modules | jvm.md |
Critical Rules
==compares references, not content — always use.equals()for strings- Override
equals()must also overridehashCode()— HashMap/HashSet break otherwise Optional.get()throws if empty — useorElse(),orElseGet(), orifPresent()- Modifying while iterating throws
ConcurrentModificationException— use Iterator.remove() - Type erasure: generic type info gone at runtime — can't do
new T()orinstanceof List<String> volatileensures visibility, not atomicity —count++still needs synchronization- Unboxing null throws NPE —
Integer i = null; int x = i;crashes Integer == Integeruses reference for values outside -128 to 127 — use.equals()- Try-with-resources auto-closes — implement
AutoCloseable, Java 7+ - Inner classes hold reference to outer — use static nested class if not needed
- Streams are single-use — can't reuse after terminal operation
thenApplyvsthenCompose— compose for chaining CompletableFutures- Records are implicitly final — can't extend, components are final
serialVersionUIDmismatch breaks deserialization — always declare explicitly