Skip to main content

RFC: Generics readability, typedef or alternative?

1 reply [Last post]
cowwoc
Offline
Joined: 2003-08-24
Points: 0

I'd really appreciate it if someone could suggest a workaround for the following problem...

A point is a Map
I want to express a List of points. So now I'm forced to refer to a List> in my code which makes it totally unreadable.

Defining class Points implements Map isn't an option because it prevents me from using AbstractMap as follows:

Points getPoints()<br />
{<br />
  return new AbstractMap()<br />
  {<br />
    ...<br />
  };<br />
}

Is there a workaround for this problem? I understand that introducing typedef to Java is problematic (even if its scope is limited to a single Java file at a time) but isn't the current situation even worse? Does anyone have a better idea?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
cowwoc
Offline
Joined: 2003-08-24
Points: 0

One workaround I found (though it's not pretty) is to declare:

[code]interface Points extends Map
abstract class AbstractPoints extends AbstractMap implements Points
class SortedPoints extends TreeMap implements Points
[/code]

In other words, you have to create a parallel hierarchy for aliasing to work.

Gili