Generics and Sort

R

Roedy Green

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
 
T

Tim Miller

Roedy said:
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.
 
R

Roedy Green

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
 
T

Thomas G. Marshall

Roedy Green coughed up:
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.
 
R

Roedy Green

{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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top