2011-08-10 112 views
0

我有這樣的,嵌套的對象和系列化

Class P { 
pub int id; 
pub P(id) { this.id = id; } 
... 
pub Set<Integer> parentTTList; 

} 

Class TT { 
pub int id; 
pub TT(id) { this.id = id; } 
pub List<P> manyPList; 
} 

List<TT> manyTTList; 

Then TT tA = new TT(1), tB = new TT(2); 
P pX = new P(-1), pY = new P(-2); 

tA.manyPList.add(pY); pY.parentTTList.add(tA.id); 

tA.manyPList.add(pX); pX.parentTTList.add(tA.id); 

tB.manyPList.add(pY); pY.parentTTList.add(tB.id); 

然後,使用ObjectOutputStream序列化TA和TB爲ByteArray,多少次我們在的pY字節組? Calss P和TT有許多關係,我們有太多人擔心尺寸。

回答

5

序列化非常聰明,可重複使用已經看到的任何引用,因此您應該只有一個pY。這在某種程度上可以解釋爲slightly related FAQ.

+0

你的幫助; TKS! – Colin

+0

@Gorca:不要忘記接受你的問題的答案 –