How to avoid instanceof?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/13204215/anything-wrong-with-instanceof-checks-here">Anything wrong with instanceof checks here?</a>  </p>
</blockquote>



<p>I have this code</p>

<pre><code>public static int getNumberOfOwned(Player owner, String type){
    int count = 0;      
    for (Field f: board.fieldList)
        if (type == "Shipping" &amp;&amp; f instanceof Shipping) 
            if (((Shipping)f).getOwnedBy() == owner)
                count++;
        else if (type == "Brewery" &amp;&amp; f instanceof Brewery) 
            if (((Brewery)f).getOwnedBy() == owner)
                count++;
    return count;
}
</code></pre>

<p>I don't think this is very elegant and future proof. How can i avoid those instanceof operators.</p>
