August 23, 201510 yr Author It would have worked even if it was an interface. But yeah, any method defined in the superclass can be invoked on the subclass instances, even if the static type is the superclass. you know im glad you mentioned the getInventory function, whenever i use just "inventory" it will return the correct number of ores on the first cycle then the next 3 it returns 0, either way here is the final code minus the removal of generics <T extends ItemContainer>int getOreCount ( T itemContainer, int... IDs) { if (itemContainer != null) return (int)itemContainer.getAmount(IDs); return 0; } public int onLoop() throws InterruptedException { log(Integer.toString(getOreCount(getInventory(),IDs[0],IDs[1]))); return random(200, 300); } which so far is working fine and ended up being way more efficient than the old code, although Im not sure if checking for a null ItemContainer reference is necessary since that never seems to be the case, tho i suppose if i don't need to check if it's null i could just narrow it down to log(Long.toString(getInventory().getAmount(IDs[0],IDs[1]))); Edited August 23, 201510 yr by senpai jinkusu
August 23, 201510 yr you know im glad you mentioned the getInventory function, whenever i use just "inventory" it will return the correct number of ores on the first cycle then the next 3 it returns 0, either way here is the final code minus the removal of generics <T extends ItemContainer>int getOreCount ( T itemContainer, int... IDs) { if (itemContainer != null) return (int)itemContainer.getAmount(IDs); return 0; } public int onLoop() throws InterruptedException { log(Integer.toString(getOreCount(getInventory(),IDs[0],IDs[1]))); return random(200, 300); } which so far is working fine and ended up being way more efficient than the old code, although Im not sure if checking for a null ItemContainer reference is necessary since that never seems to be the case, tho i suppose if i don't need to check if it's null i could just narrow it down to log(Long.toString(getInventory().getAmount(IDs[0],IDs[1]))); The default instances of Bank, Inventory, Equipment etc. will never be null, so you don't need to nullcheck them. "getInventory()" versus "inventory" is a matter of personal preference/convention. getInventory merely returns the inventory instance. It is the exact same thing.
Create an account or sign in to comment