Re: problem with TreeMap - element removal fails.
- From: Piotr Kobzda <pikob@xxxxxxxxx>
- Date: Mon, 17 Jul 2006 11:41:16 +0200
Ingo R. Homann wrote:
Well, to make the TreeMap work correctly, it is necessary that the keys implement Comparable. So it is obvious that your code cannot work.
Keys of TreeMap don't have to implement Comparable when you provide a keys Comparator to the map's constructor.
That is true reason of why:
TreeMap is defined as "TreeMap<K,V>" and not as "TreeMap<K extends Comparable,V>".
Having said this (and thinking more about it), I think it would be good if the runtime error would be thrown in the constructor (fail early)!
Impossible. TreeMap constructors have no knowledge on its generic parameters types neither its future elements types.
piotr
.
- Follow-Ups:
- Re: problem with TreeMap - element removal fails.
- From: Ingo R. Homann
- Re: problem with TreeMap - element removal fails.
- References:
- problem with TreeMap - element removal fails.
- From: tomek milewski
- Re: problem with TreeMap - element removal fails.
- From: Ingo R. Homann
- problem with TreeMap - element removal fails.
- Prev by Date: Re: Handling multiple exceptions in one exception handler block
- Next by Date: Re: Aside from googling....
- Previous by thread: Re: problem with TreeMap - element removal fails.
- Next by thread: Re: problem with TreeMap - element removal fails.
- Index(es):
Relevant Pages
|