What Carey said.
In more formal terms, you can pass sub-types of the types specified in the method definition as arguments.
For primitive arrays, the only super-type or sub-type relationships are these:
JLS 4.10.3 wrote:• If P is a primitive type, then:
– Object >1 P
– Cloneable >1 P
– java.io.Serializable >1 P
So, you can pass an array of some primitive type somewhere that is expecting exactly an array of that exact type, a perfect match.
You can also pass an array of (any) primitive type to a parameter that wants an Object
, a Cloneable
, or a java.io.Serializable
That's it, there is nothing else that fits the bill.
If you could pass an int somewhere you could pass a long, which of course you can not, it would have to copy all of the values somewhere else, extend them, let you work on them, and then try to copy them back...this would never work.
The reason you can pass an individual int somewhere that a long is needed, is solely because these are pass by value. The only work it needs to do is to extend each of those separate int parameters to long values before it enters the function.
Similarly, you can not do this:
la = ia;