How to create a generic list with Eclipse EMF?

Yves_T picture Yves_T · Jul 18, 2012 · Viewed 10.7k times · Source

I want to create a class with Eclipse EMF that contains a List with String objects. I see that Ecore has an EList but I can't change the generic type of the list.

Any idea how to do this?

Answer

Max Hohenegger picture Max Hohenegger · Jul 18, 2012

If you want to generate code that gives you an EList<String>, then add a new EAttribute to an EClass, give it the EType EString, and set its "Upper Bound" property to '-1'.

If you want to create such a list programmatically, you could use the BasicEList for example (org.eclipse.emf.common.util.BasicEList<E>):

EList<String> stringList = new BasicEList<String>();

If you want to see your other options, open the type hierarchy on: org.eclipse.emf.common.util.AbstractEList<E>