Can you use an int array as an objects parameter?

DarthBusiness :

I am very new to java programming and I am trying to create a RPG game. What I am looking to do is create a unit (playable character) that can be modified by item parameters (item stats). It seams to me it would be simple to use an array as an object parameter and then reference its contents through methods. An example of this might be having an int array that has a parameter that is used to multiply the character’s base damage or increase armor amount. My question is this, is it possible to use an array as an object parameter in the way I described? Here is an example of what the object constructor might look like:

public class Ranger {
    public Ranger(String name, int baseDamage, int[] item) {
        /* ... */
    }
}

Also, could anyone advise if there is a better system in general to accomplish what I’m trying to do?

PaulProgrammer :

Yes, there's a better way. Use a collection.

public class Ranger {
    public Ranger( String name, int baseDamage, Collection<Item> inventory) {
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=328442&siteId=1