好問題.原因當(dāng)然如@Windoze所言,有效率的考慮,但還有更深的原因.EffectiveJava2nd,Item75,Joshua大神提到:Forexample,considerthecaseofahashtable.Thephysicalrepresentationisasequenceofhashbucketscontainingkey-valueentries.Thebucketthatanentryresidesinisafunctionofthehashcodeofitskey,whichisnot,ingeneral,guaranteedtobethesamefromJVMimplementationtoJVMimplementation.Infact,itisn'tevenguaranteedtobethesamefromruntorun.Therefore,acceptingthedefaultserializedformforahashtablewouldconstituteaseriousbug.Serializinganddeserializingthehashtablecouldyieldanobjectwhoseinvariantswereseriouslycorrupt.怎么理解?看一下HashMap.get()/put()知道,讀寫Map是根據(jù)Object.hashcode()來確定從哪個bucket讀/寫.而Object.hashcode()是native方法,不同的JVM里可能是不一樣的.打個比方說,向HashMap存一個entry,key為字符串"STRING",在第一個java程序里,"STRING"的hashcode()為1,存入第1號bucket;在第二個java程序里,"STRING"的hashcode()有可能就是2,存入第2號bucket.如果用默認的串行化(Entry[]table不用transient),那么這個HashMap從第一個java程序里通過串行化導(dǎo)入第二個java程序后,其內(nèi)存分布是一樣的.這就不對了.HashMap現(xiàn)在的readObject和writeObject是把內(nèi)容輸出/輸入,把HashMap重新生成出來.