Again hashcode() question ?

thanks for your several answers,
but i want a clear and definitive answer for this assertion ?
i want to use instance of ObjectX in a HashTable.
if i overide the equals() methode for objectX, have i to do the same for hashCode(), and if yes how can i generate an integer hascode for each distinct object X.
class ObjectX {
private int x;
private int y;
public boolean equals(ObjectX ox) {
return (this.x == ox.x);
public int hasCode() {
.....how to generate an integer hashCode
}

There is no clear and definitive answer for your question. The only answer is that the hashcode calculation should involve the same variables that are involved in the equals calculation. In some way.
So in your example, two ObjectXes are "equal" if and only if their x variables are equal. So their hashCode() method should return the same value for all ObjectXes that have the same value of x. The easiest way to do this ispublic int hashCode() {
  return x;
}You can see (if you look at it for a bit) that if two ObjectXes are equal, then their x variables are equal, and hence their hashCode() methods return the same value (namely x). Clearly other methods would work just as well -- for example you could return 2x, or x squared.
Now if the equals() method compared both the x and y variables, then your hashCode() method should return some function involving both x and y. As setmuss said, x^y would do. So would x+y and x-y.
As I said, there's no definitive answer for this.

Similar Messages

  • I'm getting a new computer, I will have to download Firefox again, My question can you save your add-ons? I have reminder Firefox and I want to know if I should save the info?

    I'm getting a new computer, I will have to download Firefox again, My question can you save your add-ons? I have reminder Firefox and I want to know if I should save the info?

    You can use this extension to make a backup of the current Firefox profile folder:
    *FEBE (Firefox Extension Backup Extension): https://addons.mozilla.org/firefox/addon/febe/

  • Hashcode() question ???

    hi again,
    i understand that i need to overide the hashCode() methode for a class X if i plan to put it in a hashtable, my question now is how can i generate an unique ID for each instance of X
    thanks again for your answer

    why? I can see no reason to override hashcode if your
    object can't provide a more unique hash number then
    the default implementation.Well, the point sort of is, if you have overridden equals, then you have a better implementation. The default implementation of hashcode uses a function based mainly off memory reference, so, if you've overridden equals to key off, say a certain field (like the value of an employees' salary), it would be expected that your hashcode impelmentation also key off of that field. Other wise you could have a situation where:
    Employee one = new Employee(300);
    Employee two = new Employee(300);
    //true
    one.equals(two);
    //potentially false
    one.hashcode() == two.hashcode();since equals keys off of the salary field, while hashcode still keys off of the default implementation (memory reference).

  • Quick hashCode question

    Hi,
    ive read a few previous posts about this and am still not 100% on this. From what i understand, hashCode is worked out using the memory address unless an equals() method is implemented in which case it uses this.
    Is this right or wrong?
    Thanks
    Chris

    Read the API documentation of java.lang.Object.hashCode(). It states three conditions:
    1. the same object must return the same value for hashCode() if it is called multiple times (during the execution of the Java application)
    2. if two objects are equal according to the equals() method, a call to hashCode() of both objects must return the same value
    3. it is not required that if two objects are unequal, they have different values for hashCode().
    Furthermore:
    "As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)"
    Jesper

  • Again my question: please help me!

    Win2000 JDEV902, no application server, no database just W2000 and JDEV902:
    When I follow the tutorial "OTNDeptEmpStub" and run the class:
    Example 1 - Department numbers
    [SOAPException: faultCode=SOAP-ENV:IOException; msg=Connection refused: connect; targetException=java.net.ConnectException: Connection refused: connect]
    void org.apache.soap.SOAPException.<init>(java.lang.String, java.lang.String, java.lang.Throwable)
    void oracle.soap.transport.http.OracleSOAPHTTPConnection.send(java.net.URL, java.lang.String, java.util.Hashtable, org.apache.soap.Envelope, org.apache.soap.encoding.SOAPMappingRegistry, org.apache.soap.rpc.SOAPContext)
    org.apache.soap.rpc.Response org.apache.soap.rpc.Call.invoke(java.net.URL, java.lang.String)
    java.lang.String[] IOTNDeptEmpStub.getDeptNoArray()
    void Class1.main(java.lang.String[])
    Process exited with exit code 0.
    ======================================
    What's wrong??
    Please help, thanks Stephan

    This unfortunately is another problem ... the Web service is up but the re-deployment resulted in the incorrect WSDL being deployed. If you look in your stub, you will see a line that looks like the following:
    public String endpoint = "http://otn.oracle.com:7790/ws/deptemp"
    If you replace this URL with the following:
    public String endpoint = "http://otn.oracle.com/ws/deptemp"
    it should work fine.
    Today I just am in the midst of putting out the WSDL fixes and have updated the tutorial(s) to use a correct version of the WSDL. These changes will be out tonight or early tomorrow.
    Apologies for the inconvenience.
    Mike.

  • What are the most common questions in the forums?

    I have my own ideas about what are the questions we see asked over and over and over again in here. Everyone post your ideas here so we can compile a FAQ and maybe post it somewhere (Virum, your new site? :) )

    Please do my homework/coursework/think for me
    This has to be by far the most common type of question asked on the forums.
    Classpath questions
    HashCode questions
    Pointer vs Reference Debate (totally spurious but people spew 100's of pages arguing about something that is perfectly obvious)
    A very good Thread that is probably 1000's of entries long by now is the
    "How to get your questions answered promptly" one (or however this is called). A recap of that published somewhere would be of tremendous value, especially if it was presented as a page you had to go through before landing in the forums to post your latest "Java Challenge" aka "do my coursework" on the boards.

  • Questions About Office 365 Capabilities

    I am exploring the possibility of putting our organization's Office on, "the cloud" using Office 365 Enterprise E2. I have some questions that are important. Any help will be appreciate.
    1.  I have developed extensive VBA "code behind" on Word files and Excel workbooks that do complex operations.  For instance, I open our Outlook public folder shared contacts to do searches and populate forms and Excel cells. 
    I use NPOI calls to create downloadable Excel workbooks, etc.  I use calls to SQL to access and query databases and return data.  Is the VBA coding supported with Office 365?  If so, what restrictions might there be over my current situation,
    where Exchange and Office are hosted on our servers?
    2.  In general, what restrictions will I encounter with Exchange and Office being hosted by Microsoft, versus these tools being hosted on our servers?
    Again, crucial questions and I appreciate any help.  Thanks.
    Doug Pruiett Good News Jail & Prison Ministry Richmond, Virginia www.goodnewsjail.org

    Hi,
    Please try to use your account which logon in the Technet to sign in the Office 365 forum.
    http://community.office365.com/en-us/forums/default.aspx
    And your issues were more related to coding/programming, you'd better post them to MSND forum:
    http://social.msdn.microsoft.com/Forums/en-US/home?category=officedev&filter=alltypes&sort=lastpostdesc
    Regards,
    George Zhao
    TechNet Community Support

  • My MacBook Pro (15-inch Mid 2009) question mark on startup

    My MacBook Pro (15-inch Mid 2009) has a question mark on startup.
    I brought it to my local apple service centre and they told me that after a few tests it was the hardrive, so they changed it under-warranty. Back home I started re-installing my system and got again a question mark on startup.
    I decided to put the hardrive in a FW800 external enclosure and boot my system this way and the computer started without any problem. I reinstalled the hardrive in the MacBook Pro and again got a question mark on startup.
    I decided to buy another drive, Seagate momentus XT 500Go, transfered all my files in this new drive and I installed it inside the MacBook Pro, still the same question mark on startup. I installed it again in my FW800 external enclosure and everything worked fine.
    I decided to installed it again in the MacBook Pro, load the computer via the original Mac OSX install DVD, load the system and try to install a new fresh one on the hardrive... no hardrive were found....
    So I decided again to bring it back to the same local service centre, and they told me again it was the hardrive the problem... but they don't want to listen to me when I told them that all my hardrives can startup the computer via an external enclosure....
    So I would like your help, I think the problem come from the cable that linked the HD to the motherboard or the SATA chip inside the motherboard, but they don't want to test it !!!!
    Thanks in advance for you help, I have been without my computer since 2 weeks now and I can't afford working without it any more !!!
    Sincerely
    bosa30

    You need to take this computer to a real Apple Store. Or call AppleCare. Obviously this "local serve centre" doesn't have the skills to deal with your issue.
    I'd also check your RAM, as an easy first step. But I think the HD controller in your Mac is bad, since you can boot from an external drive.

  • How can i alow browzing in project without disable al questions?

    When preview or publish project, if I pass a question slide (move forward), then go back to previous slide (one before the question slide) and then go forward to the same question slide again, this question slide and all the rest of question slides in the project dose not enable me to answer it and i get a line response: "you did not answer this question completely".
    What can i do to allow user to thumb through slides in project (forward and back whenever he wants) without disable the questions?
    thanks!

    Hi
    thanks so much, I did mark backward movement but did not mark infinite attemps in the Quiz Preferences  'Pass Fail'. after did that it all work just fine!
    saved me!
    ofra

  • Workflow Question - Recently moved from PC to Mac

    So, let me say that I'm a die hard Windows user -- in fact, in my "day job" I own a software development company and we're a "Microsoft shop". But, my side business is Photography and I'm making the switch to the Mac & Aperture. So, what I'm hoping to get from this post is a "yes, you can do that" or a "no, you can't do that" with Aperture. I'm happy to figure out how -- I just need someone to tell me if it's possible.
    Here's my current workflow (coming from the PC - which required several applications to accomplish these steps):
    1) Import images and rename "IMG_1234.CR2" to "1234.CR2" -- essentially dropping the "IMG_" from the name. Is this possible w/ Aperture?
    2) Do all of the processing on the images (No questions here yet -- got that pretty well figured out in Aperture).
    3) Create a black & white version of each image. Currently doing this by making a duplicate version in Aperture. But, I would like it to be named "1234-BW.CR2" rather than just have "version 2" tacked on the end. Is this possible in Aperture?
    4) "Develop" the pics into jpg's. Again, the final image names should be "1234.jpg" and "1234-BW.jpg" respectively. Again, the question has to do with renaming the original & duplicate version of the image.
    5) Choose all of the color versions of the photos and then selectively pick some of the b/w versions and export them to a "Web" size along w/ Thumbnail versions that will be posted on my web site. (Again, this should be easy if I can name things like I want them to be named in question 3 & 4.)
    So, right now I'm the biggest thing that I'm having a problem with in naming the images -- how flexible is Aperture with this? I've tried to customize the naming but can't see to figure out how to simply remove the "IMG_" when importing and then how to tack on "-BW" when creating a duplicate version.
    So far I really like Aperture -- it will ultimately save me from having to use 5 different applications on the PC and thus greatly improve the efficiency of my workflow. There are some things I've noticed that would be nice -- for example, on the PC I used a program called Bibble Pro to "develop" my Canon RAW files. Bibble is a little smoother (read faster) when making some adjustments. For example, when I'm in full screen mode and adjust the exposure, contrast or sharpening Aperture is not as smooth and "real-time" as Bibble. (And, the Mac I have is the top of the line iMac made today w/ 2GB of RAM. So, I would assume that processor speed is not an issue.)
    Anyway, if you have any insight into this post please let me know. Thanks in advance for any help you can provide... If you want to see my web site to understand what I'm doing the URL is http://www.level3photography.com/proofs.aspx
    Thanks again!
    TK Herman
    [email protected]
    iMac   Mac OS X (10.4.8)  

    ...the Mac I have is the
    top of the line iMac made today w/ 2GB of RAM. So, I
    would assume that processor speed is not an issue...
    Many folks from other disciplines think that applications should, well, just run on any computer. Not so with graphics apps. Photoshop, for instance, slows if not provided a second physical hard drive for scratch disk; Aperture craves GPU hardware; both gobble RAM; etc. Existing PSCS2 Photoshop performance improves up to 8 GB RAM, and we have not yet empirically determined the max amount of RAM Aperture will benefit from but it certainly is more than 2 GB.
    iMacs are consumer machines, not pro graphics boxes, even though many folks successfully use them as such. And, "top of the line iMac made today" would include not the 7300 GT graphics but the 7600 GT graphics card and 3 GB of RAM rather than 2 GB.
    All that said, your iMac should run Aperture well if you keep the box well maintained. Just don't be surprised if you do see some hardware imposed limitations.
    -Allen Wicks

  • Simple Odd question

    Hi All,
    When you are creating an asset (as01), in the Origin Tab, there are two indicators.
    1 = Asset purchased new
    2 = Asset purchased used
    Is there is any way that we can make it like it will be mandatory for a user to check on one of these two indicator, if the user is creating a new asset?
    Current functionality allows a user the following option when creating an asset
    1 = Either check the indicator (asset purchased new) -- Structure = XNEU_AM
    2 = Either check the indicator (asset purchased old) ---  Structure = XGBR_AM
    3 = Not check any of the above indicators and still create asset master record.
    Again, my question is, can we somehow make the above mentioned # 3 option to be as a new option which is like
    4 = Either check option # 1 or check option # 2, otherwise the user is unable to proceed to create the asset master record ???
    I am thinking it has something to do with ABAP developers. Because I check the field status for Origin tab in the configuration, and it does not metion anything about supress/optional/required about the above mentioned indicators.
    Any suggestions???
    Thanks,
    Rob

    Hi,
    make field ANLA-LIFNR obligatory
    -> than you must fill XNEU or XGBR
    A.

  • Contemplating BK7- lot's of questions

    Hi everyone!  Started reading on this site and have found it very informative and I feel a bit better about filing but I still have questions that I haven't found yet here.  I am scheduled to talk w/an attorney tomorrow afternoon. A few years ago my husband lost his job and I became the sole provider.  He found a part time job and collected unemploymentt but that wasn't enough  Now he is self employed making decent money doing what he loves. During that time we survived off of my income, whatever he brought in and of course credit cards.  Last year once he was established in his new venture I started applying for cards here and there, then I made the mistake of obtaining personal loans. The approval rate and amounts became very addicting if that makes any sense.   Fast forward to now- $45k later- we are drowning and I'm kicking myself for poor choices- Debt to income ratio is way over.  We have 2 car payments up to date and we pay the mortgage on our home but with all the regular daily living expenses we can longer keep up so I am looking into filing Ch 7.  All credit lines are maxed out, store cards are not. 2 things- sadly I work for a CC company that we have 2 cards with.  The balances/CL is low on both and I thought about keeping them to save face if that makes any sense- is that even possible?  I am also afraid of loosing my cars but I read that you can reaffirm the loans?  But can I keep both is the question.  We need both to get to and from work plus we have 3 kids.   I guess in addition to my little questions I am looking for reassurance or anyone who has a similar story AND/OR can offer some helpful tips.  This is a great place, I thank you in advance for any help anyone can provide!   MBB1978Current Score reading on CK- 605 

    These questions would be best asked to a reputable BK attorney in your area.  You've done the first step and set up an attorney visit, so, see what they say. Now, the credit card piece can be tricky, since you work there.  Paying over a certain amount within a certain timeframe can be considered preferential treatment and the trustee can order the money returned to be distributed.  If, at the time you file, you have a balance on these cars, you ARE required to list them as a creditor in which they would get notice of your filing.  If you could pay it down before you file to zero balance, you would not have to list them as a creditor and they may survive your BK filing process - again, the question is how much and how quickly you do it - again, a qualified attorney would be your best bet. You more than likely can keep your cars under the state and federal exemption limits, but it depends on your lender (some lenders require a reaffirmation agreement or force you to surrender the vehicle) and your income. Good luck and keep us posted. Most of us here have been in your shoes - made bad choices or simply feel on bad luck/hard times.  We've all recovered nicely and can attest there is life at the end of a BK filing.

  • Near last question, need to know bout best way to do this...

    Thanks for the replies...this is all coming into focus now, and I cannot thank you enough for all your previous replies. Just to nail this down, and try to avoid confusing myself as ive seem to be quit apt to do on this subject matter. I have had another question...
    You said my code for setting the value looked good. Well I had gotten ahead of myself again...
    public native void setJSource(JSources obj); is actually what sets the native side...and
    public native JSources getJSourceData();
    is what sets the java side from the native side, how do i invoke the setters on the JSources thats being sent to getJSourceData as a return value? or do I not do it that way and instead have
    public native void getJSourceData(JSources theData);
    and in native code use:
    JNIEXPORT void JNICALL Java_AbfaRegion_getJSourceData (JNIEnv *env, jobject thisObj, jobject someVarsObj){  jclass clazz;  jmethodID mid;  clazz = (*env)->GetObjectClass(env,someVarsObj);  mid = (*env)->GetMethodID(env,clazz, "SetHeight", "I");  (*env)->CallVoidMethod(env,someVarsObj, mid, struct->myHeight);}
    is that the more better/jni way of doing things? instead of thinking the native code will actually return a class?
    Thanks again,
    Shane

    Your question is confusing, so I'm just going to leap to some answers.
    1. You can, of course, pass a java object to your native (C) code.
    2. You can use JNI to call "getters" on the java object. The getters can return primitives (int's, longs, ...), and they can return objects. If you design so getters return objects, ten you will have to write two levels of JNI code - calling the getters, and calling methods of objects returned by the getters.
    3. You can also use JNI to call setters on the java object. These can take as parameters either java primitive types, or objects. SO: this is one way you can return data to java from C.
    4. An alternative way to return data to java from C is to instantiate a java object (using JNI), then use JNI to call that object's setters, then return the object at the end of the C routine.

  • BOE- General Implementation Questions

    I recently joing a Medical Transportation Company which is currently using DB2 on AS400 and is in the process of moving to Mysql. The project that I'm incharge of is finding the right technology for web based report generation and making them accessible to end users to run their own reports on a day to day basis. Currently we have BOE on a very old computer with radom versions of Crystal software installed on 2-3 computers with out a report server.
    I would appreciate if someone could suggest what I need in order for me to create a separate BOE server and what are the pre-req's in order to do that. Any help is greatly appreciated.
    Please feel free to ask me questions if anything I asked is not clear
    Thanks
    Achett

    What version of BOE do you have? Anyway, BOE comes with Web Intelligence which is an excellent web-based reporting tool. It is very easy to use and very easy to learn, as long as the back-end data-mart and the universes are set up correctly.
    It depends on how many users the system is going to support, you should install it on a server. BusinessObjects is built for Windows first, and then extend to other Operating Systems later. Therefore, for optimizing performance and minimizing cost at the same time, you should use Windows Server. Windows servers are much cheaper to maintain than UNIX server, and Windows Admin are much cheaper in term of salary than UNIX Admin. So you do the math.
    The installation is quite straight-forward. You should read the Getting Started and the Admin Guide documentation first before you proceed. If you are stuck, you can always contact Tech Support if you have purchased the support contract. Otherwise, feel free to drop by again for questions.
    Hope this helps.

  • Captivate Quiz weighting of questions

    Hi,
    i'll try to explain what my question is. I would like to make an assessment/quiz in Captivate 5. The point is, we need to be able to adapt the difficulty level of the questions to the participant's answers.
    E.g. a participant answer correctly to three questions. Question 4 will then be a question that we weighted to be more difficult. He also answers correctly to this question. The following 2 questions have the same difficulty level as question 4. Participant answers correctly. Difficulty level increases again for question 7. This time, his answer is wrong, as is with question 8, but question 9 is correct (which means he answered 2 out of 3 wrong of the most difficult questions until now.). For question 10, the difficulty of the questions will again be less than for questions 7 through 9. And so on...
    Could anyone tell me if this is possible?
    Thanking you in advance,
    Ynske

    Hi Lilybiri,
    thank you for your answer.
    I am using Captivate 5. The assessment idea is, at the moment, rather rudimentary. We are looking into possibilities.
    Since it's a test for assessing knowledge of people to see if they're good enough for a job, i guess it will have a pass/fail score.
    tx
    Ynske

Maybe you are looking for

  • How do I use earphones with iphone

    I am a grandmother who doesn't use all the apps that are on the iphone. I am planning a nice vacation where I will be flying quite a lot. Please tell me how to use noise cancelling earphones with my iphone. If I download an audio book, will I be able

  • Is it possible to store data collected in a form when the device is offline?

    I am trying to figure out if this is possible. I want to collect email addresses via an interactive PDF when offline.   ie. have a text field and submit button which would save the data to the pdf or an associated data file - txt/csv etc?  Is this po

  • Locked threads, instead of hiding "reply" link change word to "Locked"

    Based on this thread: http://social.microsoft.com/Forums/en-US/cc444c7a-a838-4a16-ac57-8f315475b602/how-does-one-reply-to-a-post-i-see-no-reply-button?forum=reportabug It seems that for locked threads, people can scroll past the the "Lock" icon too q

  • Check Form RFFOUS_C

    Hi I copied the standard program and created a new form and Sap script with two pages . Requirement is once the line items are more than 12 it should go to secoend page and print all the items in second page. Please let me know how to make the system

  • Mapping Workbench

    I have been using the mapping workbench (9.0.3) against MySQL without any connection problems. I have recently upgraded to 9.0.4 and can no longer connect. I have made no changes to the classpath either in MW or in my system settings. Am I doing some