title: Why cast after an instanceOf?
body: <p>In the example below (from my coursepack), we want to give to the <code>Square</code> instance <code>c1</code> the reference of some other object <code>p1</code>, but only if those 2 are of compatible types.</p>
  <pre><code>if (p1 instanceof Square) {c1 = (Square) p1;}
  </code></pre>
  <p>What I don't understand here is that we first check that <code>p1</code> is indeed a <code>Square</code>, and then we still cast it.  If it's a <code>Square</code>, why cast?</p>
  <p>I suspect the answer lies in the distinction between apparent and actual types, but I'm confused nonetheless...</p>
  <p><strong>Edit:</strong><br />
  How would the compiler deal with:</p>
  <pre><code>if (p1 instanceof Square) {c1 = p1;}
  </code></pre>
  <p><strong>Edit2:</strong><br />
  Is the issue that <code>instanceof</code> checks for the <em>actual</em> type rather than the <em>apparent</em> type?  And then that the cast changes the <em>apparent</em> type?</p>