Use Class<?> parameter in instanceof method

I have the following method that can return different types of Storable (ex: Food, Ore). Inventory.java public Storable get(Class<? extends Storable> cls) { for (Storable storable : inventory) { if(cls.isInstance(storable)) { this.inventory.remove(storable); return storable; } } return null; } It works, however I’m forced to cast my result like below: Food food = (Food) inventory.get(Food.class);… Read More Use Class<?> parameter in instanceof method