简体   繁体   中英

Implement my own Array Method Help Java

How would I implement my own method on an element of my own array?

for example, im trying to make a inventory system that if (INVENTORY[X].isValidID() == TRUE)

Then it returns true,

how would i do that?

public void addInv(int ITEM_ID) {
    for(int x = 0; x < MAX_STORAGE; x++) {
        if(INVENTORY[x].isValidID() == true ) {

        }
    }
}

public static boolean isValidID(int X) {
    return true;
}

You are likely looking for something like this.

 public void addInv(int ITEM_ID) {
    for(int x = 0; x < MAX_STORAGE; x++) {
       if(isValidID(INVENTORY[x])) {

      }
    }
}

public static boolean isValidID(int X) {
   return true;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM