Re: problem with TreeMap - element removal fails.
- From: "Ingo R. Homann" <ihomann_spam@xxxxxx>
- Date: Mon, 17 Jul 2006 12:59:29 +0200
Hi,
Piotr Kobzda 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.
OK, yes, that's another possibility.
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.
There is a workaround for this (which I do not like):
class Foo<T> {
public Foo(Class<T> c) {
// check c by reflection
}
}
All this would of course not be necessary if generics were not implemented by type erasure...
Ciao,
Ingo
.
- References:
- problem with TreeMap - element removal fails.
- From: tomek milewski
- Re: problem with TreeMap - element removal fails.
- From: Ingo R. Homann
- Re: problem with TreeMap - element removal fails.
- From: Piotr Kobzda
- problem with TreeMap - element removal fails.
- Prev by Date: Re: JDBCExceptionReporter
- Next by Date: Re: Problem with JCombo box
- Previous by thread: Re: problem with TreeMap - element removal fails.
- Next by thread: Re: problem with TreeMap - element removal fails.
- Index(es):
Relevant Pages
|