# Code 2  in generated java classes

**URL:** <https://techcommunity.softwareag.com/t/code-2-in-generated-java-classes/57898>\
**Category:** Forum\
**Tags:** Adabas-Natural, Adabas, Adabas-Add-on-Products, Other-Adabas-add-on-products, Adabas-SOA-Gateway\
**Created:** [March 6, 2006, 7:44pm UTC](https://techcommunity.softwareag.com/t/code-2-in-generated-java-classes/57898 "2006-03-06T19:44:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guest](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/guest/32/75_2.png) [@Guest](https://techcommunity.softwareag.com/u/Guest)\
**Post date:** [March 6, 2006, 7:44pm UTC](https://techcommunity.softwareag.com/t/code-2-in-generated-java-classes/57898/1 "2006-03-06T19:44:05Z")

</div>

As I said in “Code 1 in generated java classes” there is another code snippet I would like to get some information about:

```auto
private boolean __hashCodeCalc = false;
    public synchronized int hashCode() {
        if (__hashCodeCalc) {
            return 0;
        }
        __hashCodeCalc = true;
        int _hashCode = 1;
        if (getCurrencyCode() != null) {
            _hashCode += getCurrencyCode().hashCode();
        }
        if (getAnnualSalary() != null) {
            for (int i=0;
                 i<java.lang.reflect.Array.getLength(getAnnualSalary());
                 i++) {
                java.lang.Object obj = java.lang.reflect.Array.get(getAnnualSalary(), i);
                if (obj != null &&
                    !obj.getClass().isArray()) {
                    _hashCode += obj.hashCode();
                }
            }
        }
        if (getAnnualBonus() != null) {
            for (int i=0;
                 i<java.lang.reflect.Array.getLength(getAnnualBonus());
                 i++) {
                java.lang.Object obj = java.lang.reflect.Array.get(getAnnualBonus(), i);
                if (obj != null &&
                    !obj.getClass().isArray()) {
                    _hashCode += obj.hashCode();
                }
            }
        }
        __hashCodeCalc = false;
        return _hashCode;
    }
```

Best regards Dago

---

<div class="post-metadata">

**Author:** ![Bill\_Leeney](https://avatars.discourse-cdn.com/v4/letter/b/b5e925/32.png) [@Bill\_Leeney](https://techcommunity.softwareag.com/u/Bill_Leeney)\
**Post date:** [March 7, 2006, 5:24pm UTC](https://techcommunity.softwareag.com/t/code-2-in-generated-java-classes/57898/2 "2006-03-07T17:24:31Z")

</div>

Hi again,  
In order for Java Collections to work properly, the equals() and hashCode() methods on your Object must be compatible. Compatible means that if equals() reports that two instances are the same, then the hashCode() of both instances must return the same value. An object’s HashCode is just a numeric value that can be used to store and index the object in a Hashtable (for example). So in the example you have given, both the equals and the hashCode methods have been overriden to use the currency, salary and bonus properties of the object. There’s more detail here [Yahoo | Mail, Weather, Search, Politics, News, Finance, Sports & Videos](http://www.geocities.com/technofundo/tech/java/equalhash.html)  
Best regards  
Bill

---

<div class="post-metadata">

**Author:** ![Guest](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/guest/32/75_2.png) [@Guest](https://techcommunity.softwareag.com/u/Guest)\
**Post date:** [March 7, 2006, 5:52pm UTC](https://techcommunity.softwareag.com/t/code-2-in-generated-java-classes/57898/3 "2006-03-07T17:52:59Z")

</div>

:D:D:D  
Again thanks a lot for your help.

Dago

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 2:38pm UTC](https://techcommunity.softwareag.com/t/code-2-in-generated-java-classes/57898/4 "2021-04-02T14:38:56Z")

</div>


