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?
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?
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>
Not sure if your question was answered, and what you actually want to do.
If you want to generate Java code from an .ecore file, then I provide here an example using the Eclipse Juno's Sample Ecore Model Editor of EMF (right click on the .ecore file).
Maybe it's not directly what you want, but this might be helpful for someone else.
Suppose you want a method like this in your generated Java class MyClass:
<T extends String> EList<T> getListOfType(Class<T> T)
In your Sample Ecore Model Editor you want to achieve How your method looks in the Ecore Editor by
click the arrow to "T extends ?", click on "?", in "Property" window choose within the drop down menu of EClassifier an EString, now you would see "T extends EString"
add to getListOfType a "New Child" of EGeneric Return Type
open the arrow of EEList, in the Property window choose within a drop down menu of EType Parameter a "T extends EString"
add to getListOfType a "New Child" of "EParameter"
Now youre .ecore file is ready to be used to generate a java class.