Re: Avoiding warnings about generics: 2 questions
- From: "Chris Uppal" <chris.uppal@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 17 Dec 2005 12:29:06 -0000
Scott W Gifford wrote:
> But, it still doesn't solve my original problem: is it possible to get
> rid of the warning without using @SuppressWarnings? The line with
> compareTo() warns:
>
> Type safety: The method compareTo(Object) belongs to the raw type
> Comparable. References to generic type Comparable<T> should be
> parameterized
Well, you /can/ get rid of the warning by changing the cast from (Comparable)o1
to (Comparable<Object>)o1. And, in fact, I can't think of an actual problem
that it would cause. It's still /very/ odd code, though. For instance in your
example, you are asking whether String implements Comparable<Object> (which it
does -- after erasure), and forcing it to use the compare(Object) method which
String doesn't even /declare/ !
I think you would probably be better off accepting that the type checker is
trying to tell you that your design is broken, at least with respect to the new
meaning of Comparator<T>. That means you should either change your design to
properly genericsify the whole thing, or decide that you want/need the old
meaning of Comparator. In the later case you will avoid all the generic forms,
and then just live with the warnings from the compiler (or use -source 1.4).
By and large, and without knowing what you are really trying to do, I lean
towards the former option myself.
-- chris
.
- References:
- Avoiding warnings about generics: 2 questions
- From: Scott W Gifford
- Re: Avoiding warnings about generics: 2 questions
- From: Chris Uppal
- Re: Avoiding warnings about generics: 2 questions
- From: Scott W Gifford
- Avoiding warnings about generics: 2 questions
- Prev by Date: Re: concurrency driving me crazy
- Next by Date: Re: JavaDocs for JMF?
- Previous by thread: Re: Avoiding warnings about generics: 2 questions
- Next by thread: JBOSS With IBM MQ Series
- Index(es):
Relevant Pages
|