java - Is array of primitives assigned to variable as an Object (by reference) or by value? -


i writing class of polygon , after thinking decided use arrays of x , y values , save dots.

this led me think, out of laziness, this:

int[] x, y; x = y = new int[num]; 

i know arrays classes , not considered primitive happen here?

on 1 hand, x , y arrays of primitive array partially considered primitive. may copy values new array, normal int:

int x, y; x = y = 5; 

but if not primitive x , y point same place in memory , have same variable. when edit one, second edited too.

myclass x, y; x = y = new myclass(value); 

so, question is, 1 of following ideas right?

on 1 hand, x , y arrays of primitive array partial considered primitive may copy values new array, normal int:

you correct in "arrays of primitive" not in "partial considered primitive". array array, there no partial or complete. way have defined, array of primitives means heap space assigned primitive int values stored.

but if not primitive x , y point same place in memory , have samevariable, when edit one, second edited too.

it is, later part of statement correct "same place in memory"

hope helps!


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -