Book a Demo

Author Topic: Java Generics  (Read 6616 times)

Tim Pigden

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Java Generics
« on: November 01, 2010, 07:10:53 am »
Hi, I'm struggling with a representation of Java generics.

How do I represent the following in a class diagram?

abstract class Calculator<ResultType, EntityType> {
  abstract ResultType calculate(EntityType entity);
}

class MyCalculator extends Calculator<Duration, MyEntity> {
  Duration calculate(MyEntity entity) {
    ...
  }
}

Any suggestions?
Thanks

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Java Generics
« Reply #1 on: November 03, 2010, 06:25:33 pm »
Tim,

Look for Parameterised Classes in the manual.

Geert

ukmtk

  • EA User
  • **
  • Posts: 34
  • Karma: +0/-0
    • View Profile
Re: Java Generics
« Reply #2 on: January 11, 2011, 12:44:29 am »
It seems that one can have template classes but not template interfaces? Java has template interfaces too (e.g. java.util.Collection) which was what I was attempting to model and discovered that I can't as the "details" tab does not display for interfaces?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Java Generics
« Reply #3 on: January 11, 2011, 01:03:49 am »
What you could try as a workaround is to set the parameter on the a class, then change the type of the class to interface (Via Element|Advanced|Change Type)
When you need to change anything to the details you can change it back to class.

To make sure Sparx notes this inconsistency you better request a feature as well using the link on the bottom of the page.

Geert

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Java Generics
« Reply #4 on: January 11, 2011, 09:35:00 am »
Improved support for Generics / Templates (including Templated Interfaces) is currently scheduled for the next major version of Enterprise Architect.  No timeline available for this release as yet.

apetosa

  • EA Novice
  • *
  • Posts: 14
  • Karma: +0/-0
    • View Profile
Re: Java Generics
« Reply #5 on: February 08, 2011, 11:57:01 am »
> Improved support for Generics / Templates (including Templated
> Interfaces) is currently scheduled for the next major version of
> Enterprise Architect.  No timeline available for this release as yet.
Understood. In the interim I tried Geert's suggestion. Unfortunately, once the element's type is changed to <<Interface>>, the Java type parameter disappears; changing back to <<Class>> does not return the Java type parameter.

Is a "hack" possible using Code Template Syntax and/or Tagged Values? I don't care if it looks ugly; I'm simply interested in generating a genericized Java interface.

Thanks.