你认为自己了解Java多少?你是个爱琢磨的代码侦探吗?你是否曾经花费数天时间去追踪一个由Java或其类库的陷阱和缺陷而导致的bug?你喜欢智力测验吗?本书正好适合你!
本书继承了Effective Java一书的传统,深入研究了Java编程语言及其核心类库的细微之处。本书特写了95个噩梦般的谜题,中间穿插着许多有趣的视觉幻象,寓教于乐。任何具备Java知识的人都可以理解这些谜题。但甚至是最老练的程序员也会觉得它们具有挑战性。
多数的谜题都是些小程序,其行为诡秘,不可貌相。你能指出它们会做什么吗?根据这些谜题用到的特性以及各题的详细解惑方案,本书把它们松散地分成了几个部分。这些解惑方案超越了对程序行为的简单解释,向你展示了如何一劳永逸地避免底层的陷阱与缺陷。在本书的后部有一个方便的陷阱和缺陷目录,可供以后进行参考。
一旦你解决了这些谜题,那些曾经愚弄过最具经验Java程序员的隐晦且有违直觉的语言行为,将再也无法把你骗过。
本书深入研究Java编程语言及其核心类库的细微之处,特写95个有关Java或其他类库的陷阱和缺陷的谜题,其中大多数谜题都采用短程序的形式给出。在每个谜题之后都有详细的解惑方案,这些方案在给出那些实际行为与表面上迥异的程序行为的简单解释的同时,更向读者展示了如何一劳永逸地避免底层的陷阱与缺陷。本书附录部分列出的陷阱及缺陷的目录,可供读者进一步学习参考。
本书以轻松诙谐的语言,寓教于乐的方式,由浅入深、总结归纳Java编程语言的知识点,适合具有Java知识的学习者和有编程经验的Java程序员阅读。
1 Introduction
2 Expressive Puzzlers
Puzzle 1: Oddity
Puzzle 2: Time for a Change
Puzzle 3: Long Division
Puzzle 4: It's Elementary
Puzzle 5: The Joy of Hex
Puzzle 6: Multicast
Puzzle 7: Swap Meat
Puzzle 8: Dos Equis
Puzzle 9: Tweedledum
Puzzle 10: Tweedledee
3 Puzzlers with Character
Puzzle 11: The Last Laugh
Puzzle 12: ABC
Puzzle 13: Animal Farm
Puzzle 14: Escape Rout
Puzzle 15: Hello Whirled
Puzzle 16: Line Printer
Puzzle 17: Huh?
Puzzle 18: String Cheese
Puzzle 19: Classy Fire
Puzzle 20: What's My Class?
Puzzle 21: What's My Class, Take 2
Puzzle 22: Dupe of URL
Puzzle 23: No Pain, No Gain
4 Loopy Puzzlers
Puzzle 24: A Big Delight in Every Byte
Puzzle 25: Inclement Increment
Puzzle 26: In the Loop
Puzzle 27: Shifty i' s
Puzzle 28: Looper
Puzzle 29: Bride of Looper
Puzzle 30: Son of Looper
Puzz1e 31: Ghost of Looper
Puzz1e 32: Curse of Looper
Puzzle 33: Looper Meets the Wolfman
Puzzle 34: Down for the Count
Puzzle 35: Minule by Minute
5 Exceptional Puzzlers
Puzzle 36: Indecision
Puzzle 37: Exceptionally Arcane
Puzzle 38: The Unwelcome Guest
Puzzle 39: Hello, Goodbye
Puzzle 40: The Reluctant Constructor
Puzzle 41: Field and Stream
Puzzle 42: Thrown for a Loop
Puzzle 43: Exceptionally Unsafe
Puzzle 44: Cutting Class
Puzzle 45: Exhausting Workout
6 Classy Puzzlers
Puzzle 46: The Case of the Confusing Constructor
Puzzle 47: Well, Dog My Cats!
Puzzle 48: All I Get Is Static
Puzzle 49: Larger Than Life
Puzzle 50: Not Your Type
Puzzle 51: What' s the Point?
Puzzle 52: Sum Fun
Puzzle 53: Do Your Thing
Puzzle 54: Null and Void
Puzzle 55: Creationism
7 Library Puzzlers
Puzzle 56: Big Problem
Puzzle 57: What's in a Name?
Puzzle 58: Making a Hash of It
Puzzle 59: What's the Difference?
Puzzle 60: One-Liners
Puzzle 61: The Dating Game
Puzzle 62: The Name Game
Puzzle 63: More of the Same
Puzzle 64: The Mod Squad
Puzzle 65: A Strange Saga of a Suspicious Sort
8 Classier Puzzlers
Puzzle 66: A Private Matter
Puzzle 67: All Strung Out
Puzzle 68: Shades of Gray
Puzzle 69: Fade to Black
Puzzle 70: Package Deal
Puzzle 71: Import Duty
Puzzle 72: Final Jeopardy
Puzzle 73: Your Privates Are Showing
Puzzle 74: Identity Crisis
Puzzle 75: Heads or Tails?
9 More Library Puzzlers
Puzzle 76: Ping Pong
Puzzle 77: The Lock Mess Monster
Puzzle 78: Reflection Infection
Puzzle 79: It's a Dog's Life
Puzzle 80: Further Reflection
Puzzle 81: Charred Beyond Recognition
Puzzle 82: Beer Blast
Puzzle 83: Dyslexic Monotheism
Puzzle 84: Rudely Interrupted
Puzzle 85: Lazy Initialization
10 Advanced Puzzlers
Puzzle 86: Poison-Paren Litter
Puzzle 87: Strained Relations
Puzzle 88: Raw Deal
Puzzle 89: Generic Drugs
Puzzle 90: It's Absurd, It's a Pain, It's Superclass!
Puzzle 91: Serial Killer
Puzzle 92: Twisted Pair
Puzzle 93: Class Warfare
Puzzle 94: Lost in the Shuffle
Puzzle 95: Just Desserts
A Catalog of Traps and Pitfalls
B Notes on the Illusions
References
Index