Generics and Sort

Discussion in 'Java' started by Roedy Green, Jul 12, 2005.

  1. Roedy Green

    Roedy Green Guest

    I write lines like this:

    Arrays.sort( anArray );
    Collection.sort( anArrayList );
    Collection.sort( anArrayList, new DescendingNumerically() );


    sometimes the compiler likes them and other times it does not. The
    mystery is solved. Though it complains there, the problem is miles
    away, and not at the declarations either:

    ArrayList anArraylist = new ArrayList<Entry>(200);

    The problem is in the declaration of Entry.

    It must say implements Comparable<Entry> not just implements
    Comparable. You'd think somehow the compiler would know it had to be
    comparing Entry objects but it doesn't.

    In a similar way Eclipse often complains that some symbol is undefined
    when it really means the import statement for type corresponding to
    that symbol is missing.

    --
    Bush crime family lost/embezzled $3 trillion from Pentagon.
    Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
    http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

    Canadian Mind Products, Roedy Green.
    See http://mindprod.com/iraq.html photos of Bush's war crimes
    Roedy Green, Jul 12, 2005
    #1
    1. Advertising

  2. Roedy Green

    Tim Miller Guest

    Roedy Green wrote:
    > In a similar way Eclipse often complains that some symbol is undefined
    > when it really means the import statement for type corresponding to
    > that symbol is missing.
    >

    Eclipse could not possibly tell the difference. All it sees is a
    name that is not in the typing environment. For example, if you
    had misspelt an identifier, it COULD complain that you haven't
    imported that class in which the name is defined, but that could
    be misleading because there may be no such package. As far as
    eclipse is concerned, the name is undefined because it is not in
    the "current" environment.
    Tim Miller, Jul 12, 2005
    #2
    1. Advertising

  3. Roedy Green

    Roedy Green Guest

    On Tue, 12 Jul 2005 10:00:06 +0100, Tim Miller <>
    wrote or quoted :

    >Eclipse could not possibly tell the difference. All it sees is a
    >name that is not in the typing environment. For example, if you
    >had misspelt an identifier, it COULD complain that you haven't
    >imported that class in which the name is defined, but that could
    >be misleading because there may be no such package. As far as
    >eclipse is concerned, the name is undefined because it is not in
    >the "current" environment.


    the error message is misleading, "symbol" would make you think there
    is something wrong with the name you are defining, the thing being
    added to the symbol table. The error would be clearer if they said
    Class X is undefined or simply X is undefined.

    --
    Bush crime family lost/embezzled $3 trillion from Pentagon.
    Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
    http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

    Canadian Mind Products, Roedy Green.
    See http://mindprod.com/iraq.html photos of Bush's war crimes
    Roedy Green, Jul 12, 2005
    #3
  4. Roedy Green coughed up:
    > On Tue, 12 Jul 2005 10:00:06 +0100, Tim Miller <>
    > wrote or quoted :
    >
    >> Eclipse could not possibly tell the difference. All it sees is a
    >> name that is not in the typing environment. For example, if you
    >> had misspelt an identifier, it COULD complain that you haven't
    >> imported that class in which the name is defined, but that could
    >> be misleading because there may be no such package. As far as
    >> eclipse is concerned, the name is undefined because it is not in
    >> the "current" environment.

    >
    > the error message is misleading, "symbol" would make you think there
    > is something wrong with the name you are defining, the thing being
    > added to the symbol table. The error would be clearer if they said
    > Class X is undefined or simply X is undefined.



    This is hardly cause for a thread, but you've got my curiosity a-brewing.
    And I'm trying hard to see what you mean. "symbol" is just what it is, from
    "symbol table" as you pointed out. And eclipse has no way of knowning what
    is meant by it when there is no import for it, so it is undefined.

    {shrug with palms face up} Am I missing something here?


    --
    Puzzle: You are given a deck of cards all face down
    except for 10 cards mixed in which are face up.
    If you are in a pitch black room, how do you divide
    the deck into two piles (may be uneven) that each
    contain the same number of face-up cards?
    Answer (rot13): Sebz naljurer va gur qrpx, qrny bhg
    gra pneqf naq syvc gurz bire.
    Thomas G. Marshall, Jul 13, 2005
    #4
  5. Roedy Green

    Roedy Green Guest

    On Tue, 12 Jul 2005 23:54:55 GMT, "Thomas G. Marshall"
    <> wrote or quoted
    :

    >{shrug with palms face up} Am I missing something here?


    compare Jikes, Javac and Eclipse error messages for usefulness in
    figuring out the problem. Eclipse is by far the worst. It makes up
    for it by squiggling as you pointing you to the right place the
    keystroke you make the error. You know the problem had to with what
    you just typed. Ordinary compilers don't give yo that clue.


    It is sort of like you paused after every keystroke to do a compile,
    but there is no delay.

    I found the way to work with Eclipse is never to let there be more
    than a handful of outstanding problems. It works ever so much better
    on an almost perfect program.

    --
    Bush crime family lost/embezzled $3 trillion from Pentagon.
    Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
    http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

    Canadian Mind Products, Roedy Green.
    See http://mindprod.com/iraq.html photos of Bush's war crimes
    Roedy Green, Jul 14, 2005
    #5
    1. Advertising

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. Juergen Berchtel
    Replies:
    1
    Views:
    5,990
    John C. Bollinger
    May 20, 2005
  2. Angus Comber
    Replies:
    7
    Views:
    1,155
    Richard Heathfield
    Feb 5, 2004
  3. Selection sort and bubble sort

    , Oct 16, 2007, in forum: C Programming
    Replies:
    22
    Views:
    1,754
    user923005
    Oct 19, 2007
  4. Soul
    Replies:
    0
    Views:
    517
  5. Navin
    Replies:
    1
    Views:
    690
    Ken Schaefer
    Sep 9, 2003
Loading...

Share This Page