What I was wondering aswell. On another note though, I tried it and it works for me.
Your method would make somewhat sense if you were making an api, seeing as you didnt pass a variable im assuming thats not the case, i'd use the snippet LoudPacks gave.
If you are using it to make a universal method, try this.
void dropAll(String itemName) {
if(!myPlayer().isAnimating()) {
for(Item i : getInventory().getItems()) {
if(i.getName() == itemName) i.interact("Drop"); //Would typically be your own drop method here
}
}
}