简体   繁体   中英

Returning array from method

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 ?

它只是一个引用(像java中的基本类型long,int,short,...以外的所有东西一样)是唯一的引用。

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.

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.

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