Why should we overide hashCode method when we overide equals ?

Why should we overide hashCode method when we overide equals ?

java.lang.Swapnil wrote:
Why should we overide hashCode method when we overide equals ?For the purpose of hashing, you need to override both hashcode and equal method. It is because different objects(in most cases) have different hashcode.
Edited by: Hunky322 on 28.?ub.2009 16:21

Similar Messages

  • Why should I continue using Mozilla when it fails to recognize legitimate web sites

    Why should'nt I use Windows Explorer as Mozilla refuses access ?

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    * Don't make any changes on the Safe mode start window.
    * https://support.mozilla.com/kb/Safe+Mode
    * [[Troubleshooting extensions and themes]]

  • Why can't call java method when I input  4 bytes character to the TextInput

    I am using Flex4 + Cairngorm2 + BlazeDS3.2 + Java + Spring
    Can't call java program when I input  4 bytes character in Flex.
    Example:
    Please help!

    Basic troubleshooting steps clearly outlined in the User Guide are restart, reset, restore from backup, restore as new device.
    Have you tried ALL the troubleshooting steps?  If you have and you're still having problems, then you'll need to bring your phone into Apple for evaluation and possible exchange.

  • Why does .equalsIgnoreCase() not return true when they're equal

    http://pastebin.com/m741df92b
    else if (message.matches("quit")) {
                   System.out.println("inside quit thingie");
                   // sender = sender.trim();
                   for (int i = 0; i < admins.size(); i++) {
                        String admin = admins.get(i);
                        System.out.println("testing :" + admin + ": vs :" + sender
                                  + ":");
                        if (sender.equalsIgnoreCase(admin)) {
                             System.out.println("quitting because of "
                                       + message.substring("quit".length() + 1));
                             super.quitServer(message.substring("quit".length() + 1));
                        } // end if
                   } // end for
    Output:  (the first bit is logging the incoming message)
    #TDWTFMafia:<btk> quit
    inside quit thingie
    testing :btk: vs :btk:Since posting the pastebin, I changed the code a bit so it would spit out the length along with what it's testing. that gave me
    testing :btk: (3) vs :btk: (3)

    Can you make sure the problem is not in
    System.out.println("quitting because of "+ message.substring("quit".length() + 1));
    super.quitServer(message.substring("quit".length() + 1));by replacing these 2 line with something like
    System.out.println("quitting);
    super.quitServer("quit");
    {code}
    Is the code you pasted surrounded by a try/catch statement? If message equals "quit" or something shorter your substring will throw a IndexOutOfBoundsException.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • HashCode method execution

    Dear Members :
    I have custom hashCode method in conjunction with overriden equals method, in my program and have following doubts/observations :
    [1] In order to verify whether the hashCode method is executed, I put a println statement within method, but this doesn't output when the program is run.
    [2] The program is a simple equality testing of two dates and doesn't make use of any map. I want to know when and who gives (implicit ?) call to this hashCode method, when equals method is overriden, I mean the program flow.
    Since SUN suggests to override hashCode, whenever equals method is overriden, and my program is not making use of map, how and when the hashCode method gets called and if so why my test print is not executed ?
    Thanks in advance.
    Atanu

    uj_ wrote:
    jverd wrote:
    uj_ wrote:
    One way to graciously avoid the contract is to override hashCode and let it throw an exception (or assertion) stating "hashCode not implemented. This class is not intended for use in hash-based collections" or something.What would be the advantage of doing that over just taking the 5 minutes needed to implement it properly?Who are you to stipulate other people's design needs? Just because something takes just 5 minutes doesn't mean it's the right thing to do.
    You may want a class to have an equals relation based on content but you still may not want the class to be in a hash-based collection. The most compelling reason may be that it's not immutable.
    The equals/hashCode contract is mostly a Sun promise regarding "standard" classes. Everybody else design their classes the way they see fit.Calm down UJ. I have as much right to offer my opinion as you have to offer yours. I just asked a simple question.
    The requirement that a class not be used in a hash-based collection would be silly. It's up to the user of the class how to store instances. If the fields that go into determining hashCode are mutable, then that should be a documentation issue. There are good reasons to keep hashCode and equals in sync. The only reason not to do so would be the time it takes to write the code. Since that time is trivial for any well-designed class, it's an extremely weak reason.

  • Overriding hashcode method

    Can u pls tell me friends why should definetly i override the hashcode method if i override equals method of the Object class

    Because the contracts of equals and hashCode are strongly bound to each other.
    For each objects x and y where x.equals(y) returns true x.hashCode() must be equal to y.hashCode().
    If you don't follow this convention you'll get hard-to-find bugs as soon as you use your object as a key in some kind of HashMap/HashTable/...

  • Open Question to Adobe - Why Should I Stay?

    Okay, there are now thousands of posts complaining about Adobe Creative Cloud.  There are over 31,000 signatures gathered in protest.  So far, Adobe is eerily silent.  So I am asking Adobe, why should I stay with you?  Why?  Why should I use Creative Cloud at $600 a year when I have been updating my Creative Suite about every other year for $700 (that's $350 per year)?  Why should I stay with you when you do not seem to be responding to your customer's complaints?  Why should i stay with you when you act as if everyone is so very happy with Creative Cloud and you seem to be ignoring the uproar as if it is not even happening?  Why should I stay with you when you act more and more like a monopoly that is strangling its customers?  I am a professional that has used your products for almost fifteen years.  Why on earth should I stay with you?
    Others are invited to post but I am curious if Adobe will ever respond to this. 

    Do you know a little bit of marketing rules?
    Do you know, how difficult it is to bring some one to action - espec. protest?
    Do you know about the % returning of feedback surveys (compareable... = 2-5 %)?
    (Believe me and follow regarding blogs: That are many more than 33.000 protests - no question)
    These subscribers in the last Q are because they spared all their new features to their "great CC day" on June 17th and because the discounts for CS6 users will end soon.
    These numbers (and in my eyes they are anything else than good) are a result of their forcing evil plan.
    They will drop down in August, when their are no longer discounts for CS6 users. We will see.
    Also let´s wait on the numbers, when they have to rise prices, and there is no longer income from CS6.
    700.000 of 12 Mio & the same amount of pirates (estimated) during a year a great success???
    Throwing half of the usership into garbage a good plan? = Reinventing economy?
    If you think, there will be no users who will replace Adobe with competitors - I´m one of them.
    Always was working parallel with QuarkXPress (and I like a lot - faster than InDesign - espec. in case of big documents (lots of text)). Also OWN the lifelong Right to use my Apple Video solutions (and thinking about investing to Avid now). My FreeHand still is running (also faster than Illustrator - even it is so old) ang still good for 95% of Vector Graphic. In case of Web-Design I have no great problem - Flash is slowly dying and competition is given. The only App not 100% replaceable is PS. But if it´s necessary, my MasterCollections will work the next 10 years on their actual MAC PROs (or virtualization). There is nothing I´m missing of their overwhelming solution.
    If I would estimate: CS6 will become the WIN XP of Adobe. It will still survive over decades
    (...or  Adobe is bought by better managers after it´s end)

  • When creating a tablespace why should we enable LOGGING when a database is already on ARCHIVE LOG mode

    Question :
    When creating a tablespace why should we enable LOGGING when a database is already on ARCHIVE LOG mode ?
    Example:
    Create Tablespace
    CREATE SMALLFILE TABLESPACE "TEST_DATA"
    LOGGING
    DATAFILE '+DG_TEST_DATA_01(DATAFILE)' SIZE 10G
    AUTOEXTEND ON NEXT  500K MAXSIZE 31000M
    EXTENT MANAGEMENT LOCAL
    SEGMENT SPACE MANAGEMENT AUTO;
    LOGGING: Generate redo logs for creation of tables, indexes and  partitions, and for subsequent inserts. Recoverable
    Are they not logged and not recoverable if we do not enable LOGGING? What is that ARCHIVELOG mode does?

    What is that ARCHIVELOG Mode Does?
    Whenever your database is in archive log mode , Oracle will backup the redo log files in the form of Archives so that we can recover the database to the consistent state in case of any failure.
    Archive logging is essential for production databases where the loss of a transaction might be fatal.
    Why Logging?
    Logging is safest method to ensure that all the changes made at the tablespace will be captured and available for recovery in the redo logs.
    It is just the level at which we defines:
    Force Logging at DB level
    Logging at Tablespace Level
    Logging at schema Level
    Before the existence of FORCE LOGGING, Oracle provided logging and nologging options. These two options have higher precedence at the schema object level than the tablespace level; therefore, it was possible to override the logging settings at the tablespace level with nologging setting at schema object level.

  • I am from Bangladesh. I can't log in with my gmail Apple ID. When I put in the mail and password, and press sign in, it says it has to review on iTunes. Then I am directed to opening a new account. But why should I , since I have one. Plz help :(

    I am from Bangladesh. I can't log in with my gmail Apple ID. When I put in the mail and password, and press sign in, it says it has to review on iTunes. Then I am directed to opening a new account. But why should I , since I have one. Plz help

    Hi Ishrak,
    I apologize, I'm a bit unclear on exactly what you are trying to log into with your Apple ID, or what exactly you are seeing (alert message, directions, etc) when you try to do so. If you continue to have issues with your Apple ID, you may find one or more of the articles linked from the following page helpful:
    Apple ID - Apple Support
    Regards,
    - Brenden

  • I used an American Express card to purchase my Ipad from Apple online. I have an Apple ID. why can't I use Amex as my payment method when signing in to Itunes?

    I have an Apple ID, created when I recently purchased an ipad from Apple online. I used my Amex as payment method. Why can I not use my Amex as payment method when signing in to iTunes for the first time?

    Yup, I'm a Kiwi, living in sunny Blenheim. Just seems odd that I can use Amex for purchasing in the Apple store but not in the iTunes store. Perhaps the higher charge set by Amex is not  economic for small purchases? Anyway,
    I know now what to do now - buy an iTunes gift card and enter the activation code to redeem and sign up. Sorted! Thanks Kappy for taking an interest in my query.

  • When creating a table why should we give promary key

    when creating a table why should we give promary key

    Hi Rambabu,
    Primary key is needed so as to avoid duplicate entries and ensure that there are unique entries in the table.
    For some applications, it is useful to uniquely identify the rows in a table by one or more columns so that you can process them in a specified sequence, for example. You can do this by assigning a “primary key.” The column names that are to create the table key are represented by the keywords PRIMARY KEY. The input values of the key columns defined in this way must not be a NULL value.
    You can use the primary key to insert rows in a table in the same way as you insert rows in a base table when no primary key is defined. However, the system outputs an error message if you attempt to insert an existing value into the primary key column a second time, since the uniqueness of the column is ensured by defining the primary key.
    A primary key can consist of multiple columns. However, it is unusual for a key to be constructed from more than five columns, since this makes it difficult for users to enter unique values. The arrangement of the columns behind the keywords PRIMARY KEY defines the key sequence.
    Regards,
    Sekhar

  • Why should we select all key fields when using for all entries

    Hi,
    Why should we select all key fields in our select query when using for all entries statement?
    I read about for all entries but this point was not clear in any post.
    Please explain me
    Regards,
    Subhashini

    Dear Subhasini,
    It is because FOR ALL ENTRIES deletes the duplicate entries before populating the target internal table.
    Please do an F1 on FOR ALL ENTRIES & read the SAP documentation.
    I mean how duplicate entries will not get deleted when we use this?
    Quite simple, if you select  all key fields then each entry will be unique & there will not be any duplicate entries to delete !!
    BR,
    Suhas
    Edited by: Suhas Saha on Oct 16, 2009 9:41 AM

  • Why should I download LION when it seems to have been down rated by many. See 1* and 2* reviews

    why should I download LION when it seems to have been down rated by many. See 1* and 2* reviews

    Don't, then.

  • Why should we turn off query cache when alternative UOM solution is used?

    Hi, all, Why should we turn off query cache when alternative UOM solution is used?I found it in "Checklist for Query Performance", but I dont know why.
    Please tell me if u know.
    PS: I also dont know how to turn off the cache, Need your help, thanks!

    hi ,
           I have also some confusion regarding Cache Parameters . What is the importance of cache ,  Should we delete the cache memory time to time for each query ? I have chked it in RSRT but never use the chache monitor function .

  • Why is my ipod saying 'iPod is disabled, connect to itunes' when i try connecting it to itunes, it comes up with this pop up saying it couldn't take my ipod because it has a passcode on it?, why should i connect it when it doesn't even take it!!!

    Why is my ipod saying 'iPod disabled, connect to itunes' when i try connecting it to itunes, it comes up with this pop up saying it couldn't take my ipod because theres a passcode on it?, why should i connect it when it doesn't even take it!!!

    Follow ALL  the Steps in this article  >  http://support.apple.com/kb/HT1808
    You may have to try it more than once...

Maybe you are looking for

  • New MBP internet tethering to 3GS iphone via usb - not bluethooth?

    I have a new MBP 10.5.7 & a month old 3GS iphone. I have set up internet tethering successfully & use it regularly. The only "problem" is that i can only connect via bluetooth - not usb. Im aware that you can internet tether via usb but dont know how

  • How to find List of Erroneous Workitem for single user

    Hi Experts, I need to develop an application to find out Erroneous work items for each user. Is it possible to develop an application using GP API ??? Please give any valuable inputs to my problem. Regards, Satya.

  • Index file freezes up live view dreamweaver cc 2014 .

    Hi, I have a html5 site that the index file was rendering fine yesterday in live view and today it freezes up dreamweaver cc 2014. The page will not render in live view however when viewed in a browser it views correctly. The rest of the site files w

  • Not able to connect to Active Directory through Topology manager of ODI

    Hi, We are trying to connect to Active Directory though ODI Topology manager. The details given are : +1. Using LDAP(JNDI) driver:+ username : CN=Administrator JDBC Driver name : com.sun.jndi.ldap.LdapCtxFactory JDBC URL : ldap://ten.mydomain.com:636

  • All desktop folders disappeared

    One day after I started up my ibook, I noticed all my desktop folders and info were gone. No where to be found. Luckily there wasn't a lot of important info there. Everything on the hard drive is still there, all my apps, etc. Is there anything I can