Why don't we  want to define equals() in Comparator interface...........

Comparator interface has two methods: compare() & equals(). If we implement Comparator in our class(not abstract) itz unnecessary to define equals(). Why? (If we implement an interface we should define all its methods inside the class where we implement it)....

It all hinges on what the type of Object is. Is it
of type Comparator or the parameter you expect to be
passed to compareTo?
I say that Comparator makes the most sense to me.
If you read Joshua Bloch's stuff about Comparable, he
says it's very important to make sure that compareTo
obeys the same contract as equals for that object.
Why would you want to try overriding the behavior
that might already exist in the Object that's the
parameter for compareTo? That would be bad design,
IMO. You might change the intentions of the person
who wrote that class.
%the docs say it's for comparing Comparators.
from the docs:
Additionally, this method can return true only if the specified Object is also a comparator and it imposes the same ordering as this comparator
I read that to mean that the compared objects should both be Comparators (obviously) and both result in the same ordering. seems to me the method is declared on this interface to draw attention to this addition to the contract, as much as anything else

Similar Messages

  • N00b query: Why would anyone ever want to define their own Exception class?

    I've been reading thru my Java textbook for the past couple hours.
    Exceptions are a wonderful thing. I already found several instances where I could've implemented try/cacth in my earlier programs.
    Anyway, getting back to the point. My question is, can someone give me a realistic situation/example where a custom Expcetion class is REQUIRED? (the key word here is "required"!)
    I can see why someone would want to have his own Exception class..... e.getMessage() as custom error messages are SO DAMN COOL!!!!!! :P
    hehe
    But seriously, if you are making intermidiate/advanced Java programs, would you ever REQUIRE to make your own Exception class? Afterall, even a custom made Exception class always "extends" from a pre-defined Java class, right?
    Let me make this a bit more clear... public class CustomException extends IOException{  }Now, if I am making a try/catch statement, I can simply say
    try{
    throw new CustomException;
    catch (IOException e) { }
    Now as you can see, the CustomException was caught by the catch claus, because IOException is the superclass of CustomException. So, in other words, the whole CustomException thingy didnt do anything useful.
    I know I know, I am so naive. Enlighten me >.<

    Sure. Say you want to have a system where you want to include a custom error code which maps to some internationalized error messages. You would create an Exception subclass with a field to hold that value separate from the normal "default" message. Then you could throw that exception in all your code. Other code can catch it as a plain Exception if they want and use the "default" message, which is okay if they don't really care about the error code.
    I don't think you are ever "required" to make your own exceptions. I have done so, but I don't often. It depends. See, there are plenty of Exception subclasses in the standard packages, and most of them cover many of the things you need. So more often if I'm throwing an exception, I'll be using the already existing ones, like IllegalArgumentException or IOException (whatever is relevant to the code).
    Yes, you can do what you did below with CustomException. However the reason you might do that is cuz you really want to do this:
    try {
       // call some code that may throw IOException from some standard IO package
       // or may throw CustomException from some of my methods...
    } catch (CustomException ce) {
       // handle cusotm exception
    } catch (IOException ioe) {
       // handle IO exception
    }Cuz you may want to differentiate between your exceptions vs. IOExceptions that might be thrown from some java.io class.
    Usually when you use an exception class it's a named class that relates to some condition. It may hold additional information besides the standard message, but I think most of the time it's just the class name which describes the problem. And if there isn't one that describes the problem that you're code might encounter, then create a subclass.

  • Why don't i want to sell this thing

    I just ordered a C2D MBP and have been looking for a way to sell my PB and even got an offer for it BUT i have an unhealthy attraction for this thing. This isn't the first time i've tried to sell it and i always end up holding on to it. A faster machine would be ideal and whilst the PB is no slouch its a tad slow for me.
    So whats my problem, this is the first mac i've had doubts about giving away. In fact i've considered getting it Laser etched this week but that'll mean i have to keep it till its death. Its also a shame i can't keep both...well technically. I can keep it and my parents would buy me a new Laptop in 4-5 months time or take matters into my own hands and swap the PB for a MBP now. The latter will make me more productive now whilst the former will make me suffer in productivity for 4-5 months...nothing major though.
    What do i do?

    Hi all,
    I agree with Maxit. If hadn't kept my old Ti'PB when I got my G5 I'd have been stuffed! As the G5 is "in the shop" for it's 4th (yes you read it right - 4th!!) repair session! & without my trusty Ti' Powerbook my Photographic workflow would've been halted in it's tracks - yes its slow, but it works & no workflow equals no money!
    Its always good to have a backup machine! But it maybe worth selling it for good money & buying a cheaper one - off Ebay?!? (Just know what your buying - if its fully working & reliable etc.)
    Though I must say its never nice say goodbye to a machine that has served you well all its life.
    The choice is yours. If you cant decide, flip a coin.... "ok, best out of three!" lol!
    Rory

  • WHY DON'T YOU WANT ME TO VIEW A DOWNLOADED ATTACHMENT FROM MY INBOX?

    AFTER DOWNLOADING THE DOCUMENT HAS THE FIREFOX LOGO SEAL ON IT, NOT ALLOWING ME TO OPEN. UPON CLICKING A MESSAGE POPS UP:
    "You have been signed out of your account because your internet browser has been updated 2 min ago. Please sign in again to continue. Contact customer support if problem persists. "
    IT DOESN'T CORRECT AFTER SIGNING IN - MORESO, IT ASKS ME TO SIGN IN TO YAHOO NOT MOZILLA FIREFOX.

    This issue can be caused by corrupted cookies or cookies that are blocked.
    *check the permissions on the about:permissions page and in "Tools > Page Info > Permissions"
    *https://support.mozilla.org/kb/fix-login-issues-on-websites-require-passwords
    Clear the cache and remove cookies only from websites that cause problems.
    "Clear the Cache":
    *Firefox/Tools > Options > Advanced > Network > Cached Web Content: "Clear Now"
    "Remove Cookies" from sites causing problems:
    *Firefox/Tools > Options > Privacy > "Use custom settings for history" > Cookies: "Show Cookies"

  • Why don't you have a phone #. I want to install Firefox on my ipad2 and can't get an answer. Apple says Firefox is coming for ipad2...when?

    I want to install Firefox on my ipad2 and can't get help. Apple says Firefox is coming for ipad2...when??? Why don't you have a phone# for support? Safari does not allow me to do what I need to on some websites. Help!!

    Apple's rules for their app store do not allow programs such as Firefox to be run on their iOS devices. We do have a tool to allow access to your Firefox Sync bookmarks and history on your iOS device.
    http://www.mozilla.org/en-US/mobile/home/
    https://support.mozilla.org/en-US/kb/what-firefox-sync

  • Hi there, i want to upgrade to snow leopard in order to purchase lion os from the snowleopard store. The problem is that i can't find a shop selling original snowleopard os dvd in my country. Why don't you keep an online s.leopard so we can purchase it ?!

    hi there, i want to upgrade to snow leopard in order to purchase lion os from the snowleopard store. The problem is that i can't find a shop selling original snowleopard os dvd in my country. Why don't you keep an online s.leopard version so we can purchase it ?!

    Hi,
    Have you tried your country's online Apple Store?  Snow Leopard is still available on mine, here in the UK.  Otherwise, your best chance is eBay.  You might also try CeX.
    Good luck,
    S.

  • If I don't want to define the output?

    If I don't want to define the output?
    Hello, I have one more question. more over the below.
    some function of my program, we should not show the image data (BLOB),
    so I don't define the output like as the OCI 7.3 API did (I am migrating OCI API 7.3 to 8)
    but, It occurred ORA-24374 error.
    If the SQL statement has more than 2 columns that one is normal column and the other is a BLOB, it's OK
    if I don't define the BLOB column, but If the SQL statement has only one column
    and that's the BLOB column that I don't define, I met the error.
    the OCI guide says
    SELECT name, ssn FROM employees
    WHERE empno = :empnum
    you would normally need to define two output variables, one to receive the value
    returned from the name column, and one to receive the value returned from the ssn
    column.
    Note: If you were only interested in retrieving values from the name column,
    you would not need to define an output variable for ssn.
    so, I don't know what can I do if I don't want to define the LOB column.
    thank you

    From my understanding you have some piece of logic which is inspecting each user-requested column and determining if it is acceptable to define. Can this logic be supplemented to avoid executing the statement altogether, as in :
    i.e.
    int num_total_defines = 0;
    for (each define column)
    if (column should be defined)
    define_the_column();
    num_total_defines++;
    if (!num_total_defines) goto past_stmt_execute;
    I am not too sure about the behavior change between OCI 7 & 8, but it seems like logic similar to the above might be a quick solution for your current problem.

  • Why don't my tags show up when re-saving a document that I previously tagged?

    I love the idea of tags. I use them religiously in Lightroom to organize and recall my photos. The one thing that makes tags ineffective though is the amount of effort it takes to enter them. But being a true believer of the value I do it. That being said, the way Apple has implemented tags is driving me nuts.
    I create a document
    I click save
    I enter a name and
    I enter tags  - BTY I wish I could expand the tagging window to see all the tags I have entered and all the tags that are available
    Later I make changes to my document and I want to add tags so I selected save as
    PROBLEM - All the tags that I previously saved with this document are gone. I have to renter them.  This is horrible!
    Why don't my tags show up when re-saving a document that I previously tagged? Is there anyway to get my Mac to recognize that I previously tagged this file and display my tags?
    If not, APPLE PLEASE FIX SOON.

    Christian3D
    Adobe Lightroom issues are best posted in the Adobe forums - not an Apple issue to be addressed, even though it is occurring in a OSX 'Save Dialog'.
    CCC

  • Why don't I see the option Generate under menu item File in Photoshop CC?

    Hi,
    Why don't I see the option >Generate under menu item >File in Photoshop CC?
    I want to be able to generate a edge reflow project.
    /Thors

    Please confirm if you are updated to the latest version of Photoshop CC. Go to Photoshop>About Photoshop on Mac, For Win, go to Help>About Photoshop.
    We recently released a new update. Here is teh link for more info:http://forums.adobe.com/message/5674936#5674936
    Regards
    Pragya

  • Why don't I have Boot Camp Control Panel?

    I am currently asking this in Yahoo! Answers as well:
    I just used Boot Camp Assistant around a week ago to install Windows 7 Ultimate on my Macbook Pro with Retina Display (and if it also helps find a solution: I'm also using Mountain Lion). At first, certain keyboard functions that can be used in the Mac OS (such as brightness and volume adjustment; oh, + the trackpad functions) that couldn't be used in Windows didn't exactly bother me since I was able to manage without them... until I started to play online games - which is the main reason I had to dual boot my macbook. When I already found it annoying to continuously click control+left click to perform right click, I started to look for solutions, and I noticed that most people online have said, "Oh, simply adjust your settings in the BOOT CAMP CONTROL PANEL. There should be this DIAMOND in your task bar; click on it so that you can apply changes you want. It should be there after you have installed Windows..." ... Well, thing is: in my case, it DOESN'T APPEAR! "Check your control panel," they say. "You will surely find it there." Check for me, if you will, because I seriously have no clue why I can't find it, even after checking using the Search bar...
    Now... why don't I have Boot Camp Control Panel? I find it really strange how it doesn't appear in mine when it does in most of other people's... I kinda dislike the idea of reinstalling Windows, because over the week, I've downloaded several drivers and other applications (mostly games). Is there any way I could get it without having to undergo the process of deleting and uninstalling files? I need my Mac OS for school and office work (don't ask) and I need to have my entertaining pastimes using Windows. Please don't hesitate to suggest as many ideas as you can...
    Thank you!

    It appears from your description that you did not download and install the Windows support software. It was one of the first menu items you saw when you started Boot Camp Assistant.
    Run Boot Camp Assistant again and select the menu option to download the Windows support software. Save this download as described then install it from within Windows.

  • Why don't I have the invite icon on the bottom right hand side of my calendar?  How do I get this? And why wouldn't my 4S have it and everyone else's iPhone 4 does?

    Why don't I have the invite icon on the bottom right of my calendar screen and how do I get it?
    Why wouldn't my 4S have this? But iPhone 4 users do? It is already turned on in my settings but that icon is missing in my calendar.

    Welcome to the Apple Support Communities
    Note that iCloud isn't an app. Instead, to modify iCloud settings, go to Settings > iCloud, and tick all the iCloud services you want to use on the iPad

  • Why don't have the option of using the mackie control to use consoles with motorized father

    In the audition 3.0 this option is ready with not in this version?

    Why don't have the MAC computers a hard video card????.....in this case all of my friends buy PC....Because they can buy a PC with 2 GB video card
    It partly has to do with form factor. To get a Mac Mini, iMac, MacBook, MacBook Pro, or MacBook Air as slim as they are, the video is always integrated into the main board. Windows laptops are the same way for the same reason. They aren't designed to have a video card that can be swapped out.
    The only way to buy a Mac with an actual card is the Mac Pro, where you currently have a choice of the ATI Radeon HD 5770, or an upgrade to the 5870.
    Most PCs are towers, which by design always use a video card, so you can choose pretty much whatever you want to stick in it. More than that, PCs still use plain ol' BIOS, which greatly increases the choices of cards available.
    Mac Pros don't have that luxury. Video cards for the Mac need Mac firmware on them to be recognized during startup by Open Firmware in older Macs, and EFI in newer Macs. While it's the same PCI 2.x slot, you can't just slap any video card you want in there.

  • Why don't I see the little plus sign (+)

    Why don't I see the little plus sign(+) to the right of an open tab? The one that allows you to open a new tab? I updated two other computers and there's no problem (one is using XP and the other is Windows 7). I can open a new tab by pressing "ctrl t" but I don't want to do it that way.
    Anyone else have this issue? Should I try reinstalling the update?

    Hello! Thanks for your question.
    See if this works for you. Sometimes the problem is caused by a corrupted file.
    The Reset Firefox feature can fix many issues by restoring Firefox to its factory default state while saving your essential information. Note: This will cause you to lose any Extensions, Open websites, and some Preferences.
    To Reset Firefox do the following:
    Go to Firefox > Help > Troubleshooting Information.
    Click the "Reset Firefox" button.
    Firefox will close and reset. After Firefox is done, it will show a window with the information that is imported. Click Finish.
    Firefox will open with all factory defaults applied.
    Further information can be found in the Reset Firefox – easily fix most problems article.
    Did this fix your problems? Please report back to us!
    Thank you.

  • Why don't match the values of printer ports, obtained through WMI in different ways?

    Why don't match the values of printer ports, obtained through WMI in different ways?
    $Ports = Get-WmiObject Win32_TcpIpPrinterPort -namespace "root\CIMV2" -ComputerName $ComputerName
    $Printers = Get-WmiObject Win32_Printer -namespace "root\CIMV2" -ComputerName $ComputerName
    Further, for example, on the same computer $Ports.Name returns me: (10.0.66.204 10.0.66.210 10.0.66.246 10.0.66.247)
    and $Printers.PortName (XPSPort: USB001 10.0.66.247 HPLaserJet400MFPM425dn 10.0.66.246 SHRFAX :) I.e. the values don't match to each other although they logically should be the same. Why so?
    In the end I need to get a binding the printer - the value (not the name) of the port. In Win32_Printer there is no such parameter, and there is no information about the printer in Win32_TcpIpPrinterPort. I wanted to connect them through port name but they
    don't match.

    Very unclear.
    Win32_Printer returns the bound port name.
    Get-WmiObject win32_tcpipprinterport -filter "Name='192.168.1.100_2'"
    ¯\_(ツ)_/¯

  • Why don't pictures from a slideshow made in iPhoto and then burned on to a DVD in iDVD not use the full screen?

    Why don't pictures from a slideshow made in iPhoto and then burned on to a DVD in iDVD not use the full screen?

    All I want to do is send my family the pictures for them to be able to see them on most dvds and use manually control.
    If you want set top DVD player playback, I suggest you create a a series of slideshows IN iDVD that each contain a MAXIMUM of 99 images. Do not create the slideshow in iPhoto or iMovie.
    Is there an easier way to do this, bypassing iDVD?
    Some DVD players will play a disc containing jpeg images

Maybe you are looking for

  • Accordion widget

    Hello! I have a question, why not work accordion widgets and thumbnails when I upload it via FTP to my server? Already contacted my hosting provider asking if they had the solution, I gave my directory permissions and widgets do not work. another thi

  • Catch HTTP 500 Internal Server Error

    Hi, in our RFC->XI->SOAP scenario we want to call a WebService from XI via SOAP Adapter. If an error occurs on the webserver, I receive a SAP error message with the following text: com.sap.aii.af.ra.ms.api.DeliveryException: Failed to call the endpoi

  • Simplest screenshot process

    Hi, I have read a lot of web literature about screenshots on OS X 10.6. but I did not find the missing software/process/keyboard trick. Does anyone know a software that just let me do the 3 following steps: 1. Make a keyboard combination to make appe

  • ITunes 11.1.5 (5) -How to Adding Artwork from scan not working

    I'm reading in a bunch of old CDs.  I am scaning the artwork.  I get the Info window with the Artwork prompt.  I can copy/drag the artwork in and it displays correctly. Permissions seem OK. OK does nothing... ??? can't find help ... that works.  Beli

  • BEx error: No roll storage space available

    Hi, While running a Bex query, i goth the following message and the query run was terminated "No roll storage space of length 96 available for OCCURS area".Can you please let me know what this roll storage space referes to and how this can be correct