๐ค
Java
Write robust Java avoiding null traps, equality bugs, and concurrency pitfalls.
ๅฎๅ
จ้่ฟ
ๆ่ฝ่ฏดๆ
name: Java slug: java version: 1.0.1 description: Write robust Java avoiding null traps, equality bugs, and concurrency pitfalls. metadata: {"clawdbot":{"emoji":"โ","requires":{"bins":["java","javac"]},"os":["linux","darwin","win32"]}}
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
ๅฆไฝไฝฟ็จใJavaใ๏ผ
- ๆๅผๅฐ้พ่พAI๏ผWeb ๆ iOS App๏ผ
- ็นๅปไธๆนใ็ซๅณไฝฟ็จใๆ้ฎ๏ผๆๅจๅฏน่ฏๆกไธญ่พๅ ฅไปปๅกๆ่ฟฐ
- ๅฐ้พ่พAI ไผ่ชๅจๅน้ ๅนถ่ฐ็จใJavaใๆ่ฝๅฎๆไปปๅก
- ็ปๆๅณๆถๅ็ฐ๏ผๆฏๆ็ปง็ปญๅฏน่ฏไผๅ