title: How can hashing Long ids to integer ids be safe?
body: <p>I just can't come up with a better solution than this.</p>
  
  <p>Simple example: I have meals. Each meal has a description but those come in different languages. That is why a <code>MealDescription</code> consists of a primary key <code>(MealId, LanguageId)</code>. So far so good. </p>
  
  <p><a href="http://java.boot.by/scbcd5-guide/ch05s03.html" rel="nofollow">This guide</a> here tells me that I have to implement <code>equals()</code> and <code>hashCode()</code> but is it safe to do something like this:</p>
  
  <pre><code>@Override
  public int hashCode() {
      return (int) mealId.hashCode() + languageId.hashCode();
  }
  </code></pre>
  
  <p>if <code>mealId</code> and <code>languageId</code> are actually of type <code>Long</code> like they have to be since they are ids? </p>
  
  <p>The guide I am referring to does the same:</p>
  
  <pre><code>private String name;
  private long id;
  // ..
  public int hashCode() {
      return (int) name.hashCode() + id; 
  }
  </code></pre>
  
  <p>So how does that work out?</p>