I have the following generic class header in Java:
class OrganizedGroup <T extends Leader>
The class represents an organized group. For instance, a music group would have a music leader, an enterprise would have a boss...
How can I represent the condition T extends Leader using UML?
REMARK/EDIT:
There are different so questions that ask about generics and UML. However, my question asks about and additional restriction the parameter should be shown in the diagram as subclass of another class.
You can also use more than one type parameter in generics in Java, you just need to pass specify another type parameter in the angle brackets separated by comma.
A Generic class can have muliple type parameters.
A generic method can have one or more type parameters, such as the "T" in countOccurrences.
Generics means parameterized types. The idea is to allow type (Integer, String, … etc., and user-defined types) to be a parameter to methods, classes, and interfaces. Using Generics, it is possible to create classes that work with different data types.
You would show that as template parameter with a constraint as such:
Note: actually I reverse engineered the class with Enterprise Architect and this is the result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With