f2()
{
Collection c = new HashSet();
//...
g2( c.iterator() );
}
g2( Iterator i )
{
while( i.hasNext() )
do_something_with( i.next() );
}
g2()方法現在能夠遍歷Collection的派生,就像你能夠從Map中得到的鍵值對。事實上,你能夠寫iterator,它產生數據,代替遍歷一個Collection。你能夠寫iterator,它從測試的框架或者文件中得到信息。這會有巨大的靈活性。
文章來源于領測軟件測試網 http://www.kjueaiud.com/