Skip to main content

Question regarding Java Generics

2 replies [Last post]
Joined: 2008-12-06

Fellow members
I am in the process of re-writing a java application to include Java generics.
I have the following statement which I would like to ask you all as to how to rewrite it using Java generics:

SortedMap _topPLs = Collections.synchronizedSortedMap(new TreeMap());

where the map contains:

Note: "long" is the primitive long and not the Object "Long".

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2014-03-13

with sortedMap you cannot also use Collections.synchronizedSortedMap(new TreeMap()), except if you have multiThread programn, juse instanciate it with a basic way;

SortedMap> sortedMap = new TreeMap();

Joined: 2005-11-01

The Java collections only support objects not primitives.
There are other libraries such as Trove4j which support primitives.