| Author |
Why will TreeMap<K,V>(Comparator) not compile?
|
Thomas Kennedy
Ranch Hand
Joined: Jan 20, 2008
Posts: 137
|
|
The compiler won't let me do this:
It says:
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?
|
Costs matter. Justice lies in processes not outcomes. Crime is caused by criminals.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16817
|
|
TreeMap takes a Comparator that compares the keys -- not the values.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Thomas Kennedy
Ranch Hand
Joined: Jan 20, 2008
Posts: 137
|
|
Right, thank you!
TreeMap<Integer, mapx> m = new TreeMap<Integer,mapx>(new mapdesc());
class mapdesc implements Comparator<Integer>
|
 |
 |
|
|
subject: Why will TreeMap<K,V>(Comparator) not compile?
|
|
|