在COMPIERE2的MTab類中有這樣一段程式碼:

dragon8943發表於2003-05-07

在COMPIERE2的MTab類中有這樣一段程式碼:

public synchronized void addDataStatusListener(DataStatusListener l)
	{
		Vector v = m_dataStatusListeners == null ? new Vector(2) : (Vector) m_dataStatusListeners.clone();
		if (!v.contains(l))
		{
			v.addElement(l);
			m_dataStatusListeners = v;
		}
}

我的問題是:

The implementation seems to be strange. If I were the author, I would write the following codes:

If(m_dataStatusListeners==null)
m_dataStatusListeners=new Vector(2);
if(!m_dataStatusListeners.contains(l))
v.addElement(l);

Is the second code segment better or does the first code segment have some advanages ?

<p class="indent">

相關文章