Does anyone here know Java? I have run into a small problem that I can not fix.

  • Customizer

    I have run into a small problem, that I can not fix.  And I need help.

    If you know Java, and have a small amount of time to help me, please let me know.

    I can pm more details, but essentially, the problem is thus:

    I have an object, which has its own hashcode, equals, and tostring functions.

    The hashcode is just the hashcode of the toString.  The toString includes only 2 variables in it.  It contains the name of the Object, and the name of the object that it is “attached to”.  Neither of these can change, they are both final and created when the object is created.

    When created, the hashcode of this particular problem object is -1444968155

    This object, is put into a LinkedHashMap <myobject, boolean=“”>(and when it is put in, the hashcode is the same).  This object is the only thing in the hashmap.  The boolean we put it in with is “true”.

    Later, we called HashMap.get(object), and we get null.
    However, I get the object out of the hashmap, I find that its hashmap is still the same.

    At no point does the hashmap change, at no point does the object change, and indeed the object we are calling with .get(object) is == and .equals() to the object in the hashmap.

    I have no idea how this is possible that I am getting null here, and I need some help since I don’t actually know java that well.

    thx,
    veqryn</myobject,>

  • '12

    post some code, specifically the object with the equals and gethashcode imlementations and the code accessing it.

  • Customizer

  • Customizer

    I can do another work around with strings instead, which is easier

    however, the problem is, why the hell is this happening at all?

    besides, actually, your solution would not solve the problem because the objects are not deserialized before the hashcode is taken, meaning that the saved hashcode integer will be zero, no matter what it really should be

  • '12

    Oh, I thought the problem was that the main object’s two attached objects (the ones used in the hashcode computation) weren’t being de-serialized, but if none of the main object’s fields are being deserialized then yes, that won’t work.

  • Customizer

    as i have found out, this is actually a problem with Java itself, not my code

    you may not ever have circular references + hashmaps mixed together, or the deserializer will hate you and make your life miserable

    lesson learned i guess


  • Have you worked-around this issue or are you still looking for some assistance?  PM me if this is still an open issue.

    Mot

  • Customizer

    its closed

    though if you know java and are interested in triplea, we are always open to contributors


  • Thanks Veqryn, I’ll keep that in mind.

    Actually, I made some code contributions to TripleA back in the old days.  Basically responded to a post like this and fixed the map rendering so it would work on Macs.  Long time ago though…

    Cheers,
    Mot

Suggested Topics

Axis & Allies Boardgaming Custom Painted Miniatures

33

Online

17.0k

Users

39.3k

Topics

1.7m

Posts