java - Create Enumeration of objects -


i need create java.util.enumeration of fruit objects can pass method during test. it's legacy code , cannot change method signature.

public void get(enumeration<fruit> fruits){} 

my fruit class:

public class fruit{     string name;     //getters , setters    } 

how can create enumeration of fruit objects?

you can use collections.enumeration(collection<t>) method convert collection, such list<fruit>, enumeration<fruit>:

list<fruit> fruits = new arraylist<>(); fruits.add(new fruit()); enumeration<fruit> fruitenumeration = collections.enumeration(fruits); 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -