Reputation: 4380
In my class, I have a method that returns an array like this.
double arrValues[] = ClassX.getValues();
I wonder that, does the array size have any influence on performance. Are there any copy operation for arrValues[] or is it only a reference return ?
Upvotes: 1
Views: 232
Reputation: 162851
In Java, Object types are returned by reference and primitive types are returned by value. Arrays are full blown Objects in Java. Therefore, in your example, the array is returned by reference and no copy is made.
Upvotes: 3
Reputation: 10776
There's no information about the cost of constructing the array (how much that is affected by size is unknown).
Aside from that, what is returned is just a reference to the array constructed in getValues()
, so the act of returning the array has no real performance impact.
Upvotes: 3
Reputation: 39753
It's only a reference (like everything except the basic types long, int, short, ...) in java is a only reference).
Upvotes: 3