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
Post a Comment