Re: Avoiding warnings about generics: 2 questions



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


.



Relevant Pages

  • Re: Trial Expired Warning With OEM office installed.
    ... I dont need to uninstall office, I just need to get rid of the trial warning. ... OEM version with the same results. ...
    (microsoft.public.office.misc)
  • Re: "Your computer has been infected with malware" windows update
    ... removers and most of them come back clean or have removed the stuff they ... now how do I get rid of this warning. ... > Use noahdfear's SmitFraud and SpyAxe removal tool -- SmitRem.exe ...
    (microsoft.public.windowsxp.perform_maintain)
  • 0% available RIDs in the current pool
    ... I let the 2nd DC offline too long. ... REPLICATION-RECEIVED LATENCY WARNING ... sbspmenet.PMENET.local is the RID Master ... Warning:Next rid pool not allocated ...
    (microsoft.public.windows.server.active_directory)
  • Re: Setup for unexposed-to-internet domain.
    ... I got rid of every single warning now. ... What they mean and how can I get rid of them? ... MS DTC could not correctly process a DC Promotion/Demotion event. ... ntinue to function and will use the existing security settings. ...
    (microsoft.public.windows.server.setup)
  • Re: Setup for unexposed-to-internet domain.
    ... I got rid of every single warning now. ... What they mean and how can I get rid of them? ... MS DTC could not correctly process a DC Promotion/Demotion event. ... ntinue to function and will use the existing security settings. ...
    (microsoft.public.windows.server.setup)