Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why will TreeMap<K,V>(Comparator) not compile?

 
Thomas Kennedy
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler won't let me do this:



It says:

mapc.java:13: cannot find symbol
symbol : constructor TreeMap(mapsortd)
location: class java.util.TreeMap<java.lang.Integer,mapc>
TreeMap<Integer,mapc> d = new TreeMap<Integer,mapc>(desc)
^


It seems TreeMap can use generics, or a Comparator, but not both. I don't quite see why the compiler would object to this. Can anyone explain this?
 
Henry Wong
author
Marshal
Pie
Posts: 21117
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TreeMap takes a Comparator that compares the keys -- not the values.

Henry
 
Thomas Kennedy
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, thank you!

TreeMap<Integer, mapx> m = new TreeMap<Integer,mapx>(new mapdesc());

class mapdesc implements Comparator<Integer>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic