Unchecked invocation sort

Discussion in 'Java' started by -, Aug 14, 2005.

  1. -

    - Guest

    I have :

    Type safety: Unchecked invocation sort(List, Comparator) of the generic
    method sort(List<T>, Comparator<? super T>) of type Collections


    for this statement:

    Collections.sort(list, createComparator());

    How can I get rid of the warning?
     
    -, Aug 14, 2005
    #1
    1. Advertisements

  2. "-" <> schrieb im Newsbeitrag
    news:...
    >I have :
    >
    > Type safety: Unchecked invocation sort(List, Comparator) of the generic
    > method sort(List<T>, Comparator<? super T>) of type Collections
    >
    >
    > for this statement:
    >
    > Collections.sort(list, createComparator());
    >
    > How can I get rid of the warning?


    list has to be a List on a type T like List<String> and returntype of
    createComparator() has to be a Comparator on the same type T as list (or a
    supertype of T), e.g. Comparator<String>.

    If you ensure this you won't get any classcast exceptions at runtime (and no
    warnings at compiletime of course).

    Regards
    Sebastian
     
    Sebastian Scheid, Aug 14, 2005
    #2
    1. Advertisements

  3. -

    Roedy Green Guest

    Roedy Green, Aug 14, 2005
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nobody
    Replies:
    0
    Views:
    732
    nobody
    Jun 1, 2004
  2. JerryJ
    Replies:
    11
    Views:
    1,628
    Dave Moore
    Apr 28, 2004
  3. John Black
    Replies:
    6
    Views:
    2,353
    John Harrison
    May 28, 2004
  4. Angus Comber
    Replies:
    7
    Views:
    1,494
    Richard Heathfield
    Feb 5, 2004
  5. Replies:
    10
    Views:
    790
    Xah Lee
    Sep 8, 2006
  6. Replies:
    18
    Views:
    648
    Xah Lee
    Sep 8, 2006
  7. RVic
    Replies:
    19
    Views:
    1,729
  8. Navin
    Replies:
    1
    Views:
    1,135
    Ken Schaefer
    Sep 9, 2003
Loading...