title: Passing class to use instanceof in a function
body: <p>I have a class structure:</p>
  <pre><code>class BonusCard{
  }
  
  class AddResourceCard extends BonusCard{
  
  }
  
  class AddGoldCard extends BonusCard{
  
  }
  </code></pre>
  <p>Now, I also have a function in which I want to pass AddResourceCard or AddGoldCard and in someones Inventory I want to check if an object in that Inventory is an instance of the class that I put into the function.</p>
  <pre><code>private void removeCardFromPlayer(Player player, BonusCard cardToRemove){
      for(BonusCard card : player.getInventory().getBonusCards()){
          if(card instanceof cardToRemove.getClass()){ //this line doesn't work sadly
              player.getInventory().getBonusCards().remove(card);
              break;
          }
      }
  }
  </code></pre>
  <p>A function call should look like this:</p>
  <pre><code>removeCardFromPlayer(player, AddResourceCard);
  </code></pre>
  <p>or</p>
  <pre><code>removeCardFromPlayer(player, AddGoldCard);
  </code></pre>
  <p>There should be an easy straightforward way to accomplish what I'm trying to do, I just don't really know what to search for to be completely honest.</p>