๋ณธ๋ฌธ์œผ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ
ๅฐ้พ™่™พๅฐ้พ™่™พAI
๐Ÿค–

Java

Write robust Java avoiding null traps, equality bugs, and concurrency pitfalls.

ไธ‹่ฝฝ3.8k
ๆ˜Ÿๆ ‡9
็‰ˆๆœฌ1.0.1
ๅ†™ไฝœๅˆ›ไฝœ
ๅฎ‰ๅ…จ้€š่ฟ‡

ๆŠ€่ƒฝ่ฏดๆ˜Ž


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

TopicFile
Nulls, Optional, autoboxingnulls.md
Collections and iteration trapscollections.md
Generics and type erasuregenerics.md
Concurrency and synchronizationconcurrency.md
Classes, inheritance, memoryclasses.md
Streams and CompletableFuturestreams.md
Testing (JUnit, Mockito)testing.md
JVM, GC, modulesjvm.md

Critical Rules

  • == compares references, not content โ€” always use .equals() for strings
  • Override equals() must also override hashCode() โ€” HashMap/HashSet break otherwise
  • Optional.get() throws if empty โ€” use orElse(), orElseGet(), or ifPresent()
  • Modifying while iterating throws ConcurrentModificationException โ€” use Iterator.remove()
  • Type erasure: generic type info gone at runtime โ€” can't do new T() or instanceof List<String>
  • volatile ensures visibility, not atomicity โ€” count++ still needs synchronization
  • Unboxing null throws NPE โ€” Integer i = null; int x = i; crashes
  • Integer == Integer uses 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
  • thenApply vs thenCompose โ€” compose for chaining CompletableFutures
  • Records are implicitly final โ€” can't extend, components are final
  • serialVersionUID mismatch breaks deserialization โ€” always declare explicitly

ๅฆ‚ไฝ•ไฝฟ็”จใ€ŒJavaใ€๏ผŸ

  1. ๆ‰“ๅผ€ๅฐ้พ™่™พAI๏ผˆWeb ๆˆ– iOS App๏ผ‰
  2. ็‚นๅ‡ปไธŠๆ–นใ€Œ็ซ‹ๅณไฝฟ็”จใ€ๆŒ‰้’ฎ๏ผŒๆˆ–ๅœจๅฏน่ฏๆก†ไธญ่พ“ๅ…ฅไปปๅŠกๆ่ฟฐ
  3. ๅฐ้พ™่™พAI ไผš่‡ชๅŠจๅŒน้…ๅนถ่ฐƒ็”จใ€ŒJavaใ€ๆŠ€่ƒฝๅฎŒๆˆไปปๅŠก
  4. ็ป“ๆžœๅณๆ—ถๅ‘ˆ็Žฐ๏ผŒๆ”ฏๆŒ็ปง็ปญๅฏน่ฏไผ˜ๅŒ–

็›ธๅ…ณๆŠ€่ƒฝ