Passing by reference in java

I’m trying to instantiate an object and set its parent in a function by passing the parent object in. I believe I need to pass by reference to fix this, but adding an & in the declaration sends an error. any better way to do this?

function index(parentobject, parentname, x, y, z)
{	
	newobject = Instantiate(object, Vector3(x, y, z), Quaternion.identity);
	stacktop++;
	newobject.parent = parentobject;				//this line causes errors
	//newobject.parent = transform.Find(parentname);	//this just caused more problems
}

A few things: 1) Unity doesn’t use Java. 2) You need to declare the types in your function (which should fix the actual problem). 3) Classes are always passed by reference; you don’t have to do anything.

Try:

function index(parentobject:Transform, parentname:String, vec:Vector3)
{   
    var newobject = Instantiate(object, vec, Quaternion.identity);
    stacktop++;
    newobject.parent = parentobject;       
}

I am not totally sure about it for other languages but in C++ you cannot reassign a reference. Maybe this is your issue here.
In my example I declare a new variable.