Question & Answer
Question
How do you model generalization to an Instance of Generic Class in UML to Java Transformation to get the generated code: Public class CustomerList extends ArrayList
Answer
- Attached is a model which illustrates how to model a generalization to an instance of a generic class for consumption by the Java transformations. A Java transformation profile is required.
- Open the diagram FreeformDiagram1 to view how the classes and relationships are modeled.
- After running the UML to Java transformation, the generated code will be:
public class ArrayList<E> {
public void add(E o) { }
public void remove(Integer index) { }
public void get(Integer index) { }
}
public class Customer {
private String name;
private String address;
}
public class CustomerList extends ArrayList<Customer> {
}
- The following article titled Defining Generics with UML Templates describes how EMF/ecore translates Java generics to UML which is a basis for how it is done in the Java transformations.
Was this topic helpful?
Document Information
Modified date:
23 June 2018
UID
swg21404919