Re: [心得] 序列化的小細節
※ 引述《NTUtzboy (台大資男喲)》之銘言:
: 問題出在這:(節錄自J2SE1.4 API)
: The default serialization mechanism for an object writes the class of the
: object, the class signature, and the values of all non-transient and non-static
: fields. References to other objects (except in transient or static fields)
: cause those objects to be written also. Multiple references to a single object
: are encoded using a reference sharing mechanism so that graphs of objects can
: be restored to the same shape as when the original was written.
: 所以"a.object"儲存了兩個物件, "b.object"也同樣儲存了兩個物件
: (不信的話可以直接把a.object檔打開看, 一定看的懂的...)
: 因此讀取的結果是, A有兩個instances, B也有兩個
: 其中某個A.b是指向一個B instance; 另一個A的refernce b則是指向另一個B instance
: 自己畫畫圖就很清楚了...
: 不過也很感謝p大找出這個問題呢:)
: ※ 引述《PsMonkey (痞子軍團團長)》之銘言:
: : 請原諒我幫忙加個註解...
: : (坦白說,我翻來翻去,看好久才知道確定差異在哪 XDXD)
: : //這是會導致 reference 失敗的寫法
: : //差異點在於,這邊存在兩個不同的檔案當中
: : 我比較想知道,這時候的 a.b 會指到哪裡去 @__@???
: : 為甚麼 a.b.a 又會指回來自己 @__@???
不敢當,討論區本就互相交流嘛。
版大問的問題,N大也幫我回答了呀...^^
想說兩種寫法都不會有任何警告,是很容易忽略的細節,
所以才提出來給大家參考...^^
不然有互相參照的物件在網路傳或在硬碟保存的時候,
多出來的reference可能讓程式邏輯出錯呢。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.71.41.202
討論串 (同標題文章)