title: Class with the hashcode function
body: <p>I would like to check if the <code>hashcode</code> function is used in the right way in the above code. I noticed that the <code>map</code> has some strange null and 0 values instead of {1,2,3}.</p>
  
  <pre><code>public class Test {
  
  public static void main(String[] args) {
      int[] array = {1,2,3}; 
      Map&lt;Row, Integer&gt; map = map(array);
  }
  
  static class Row extends Object {
          private int value;
          private volatile int hashCode = 0;
  
          public Row(int val) {
              this.value = val;
          }
  
          @Override
          public boolean equals(Object obj) {
              if(this == obj)
                  return true;
              if((obj == null) || (obj.getClass() != this.getClass()))
                  return false;
              // object must be Row at this point
              Row row = (Row)obj;
                  return (value == row.value);
          }
  
          @Override
          public int hashCode () {
              final int multiplier = 7;
              if (hashCode == 0) {
                  int code = 31;
                  code = multiplier * code + value;
                  hashCode = code;
              }
              return hashCode;
          }
      }
  
      private static Map&lt;Row, Integer&gt; map(int[] array) {
            Map&lt;Row, Integer&gt; arrayMap = new HashMap&lt;Row, Integer&gt;();
            for (int i=0; i&lt;array.length; i++)
                  arrayMap.put(new Row(array[i]), i);
            return arrayMap;
      }
  }
  </code></pre>