JOIN
Get Time
forums   
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat (newest first)  | Threaded  | Tree
Previous Thread  |  Next Thread
Comparer? | Reply
Er, Java doesn't have a Comparer interface - the one you're looking for is Comparator. I suppose the confusion was probably because the C# interface is called IComparer...might confuse a few newbies, so I figured I'd mention it.
Re: Comparer? (response to post by abstractwhiz) | Reply
Good catch, you are absolutely correct. (And you correctly pointed out the reason as well)
Re: Comparer? (response to post by abstractwhiz) | Reply
Or do you mean Comparable?
Re: Comparer? (response to post by dplass) | Reply
If the objects you're sorting implement Comparable, you don't need a Comparator (unless you want to use a different ordering from the one they implement). Comparable has compareTo(other object), Comparator has compare(object1, object2).
Re: Comparer? (response to post by Kawigi) | Reply
Exactly. The Comparer (in C#) that I was referring to would be the same as Comparator in Java. I did also mention the Comparable interface, which is so named in both APIs. The basic functionality is the same either way.
Re: Comparer? (response to post by Kawigi) | Reply
interesting comparison of interfaces (sorry - couldn't help myself...)
Re: Comparer? (response to post by Pops) | Reply
Next week: How to make a sorted list of Comparators.
Re: Comparer? (response to post by Kawigi) | Reply
I believe this problem is NP-Hard undecidable.
Re: Comparer? (response to post by TangentZ) | Reply
Nonsense - just because the output of a problem is unuseful doesn't mean that it's undecidable.

The problem is that you need a class that implements Comparator<Comparator>.
Re: Comparer? (response to post by timmac) | Reply
Hehe - I have this somewhat uncanny ability of spotting stuff like this, even when I just skim something. Gaffes just seem to jump out of the page at me...I've startled quite a few people with it on occasion.

Now if only I could figure out how to do this for code, I'd be the king of the challenge phase...*sigh*...
Re: Comparer? (response to post by abstractwhiz) | Reply
Well, the compiler catches this specific sort of problem before challenging would. But it would make you the king of Teaching Assistants for beginning programming classes.
Re: Comparer? (response to post by abstractwhiz) | Reply
Heh, I'm the same way. I've been known to interrupt a presenter with "You know, there's a typo on that PowerPoint slide"...
Re: Comparer? (response to post by dplass) | Reply
Well once my "Data Structure" Lecturer......shouted at me saying I am disturbing...

When I atleast pointed out 12-15 silly typo's in abt 10 min....

(Well I was in no mood of study that time) :)

<There are plenty of these incedences...>
Re: Comparer? (response to post by dplass) | Reply
If I remember correctly, intel did a presentation at the TCO'03 that either showed a bunch of code or code was the background to some slide that contained an error - very wrong audience to do that with...
Re: Comparer? (response to post by dplass) | Reply
It really comes in handy, though - last year they made me assistant editor of one of the college magazines, and I left the editor reeling when we went over a bunch of articles together. I read pretty fast, and she wasn't that comfortable reading on a computer, and I was pointing out spelling errors and grammatical screwups at breakneck speed. Eventually we decided it was better if I did it alone. :)

The downside of that was reading the terrible English in which people wrote their articles - I had a vague feeling of disorientation for about a week :). I ended up rewriting huge parts of them, confirming my theory that most engineering students can't write to save their lives...
RSS