title: What is the difference between being shallowly and deeply equal? How is this applied to caching?
body: <p>Found the following in my notes, but I am unable to make sense of it:</p>
  
  <blockquote>
    <p>Primitive type wrapper classes implement caching for a limited number
    of values.<br>
    This guarantees that a limited number of deeply equal wrapper objects are
    also shallowly equal:
    If <code>o1.equals( o2 )</code> then <code>o1 == o2</code>.<br>
    For example, <code>new Integer( 0 ) == new Integer( 0 )</code>.<br>
    In general this does not always work.<br>
    For example, new Integer( 666 ) == new Integer( 666 )<br>
    may not hold.<br>
    The reason for caching is that it saves memory.<br>
    In general caching works for “small” primitive values.</p>
  </blockquote>
  
  <p>I don't understand what is meant by this, or what the difference is between a deep (.equals()) and shallow(==) equals. I know in practice, .equals must be used to objects and == for Integral values, but the actual reasoning for this alludes me.</p>
  
  <p>I assume by the names that shallow maybe just checks that both the values are of the same type and name, which deep checks that both variables point to the same object? I don't see how the caching would come into play here though, or why it would be useful.</p>