S
Sean Hsien
Hi all,
I'm a newbie in Java. Was wondering what is the behaviour for the code
below:
myType obj = foo();
where the function foo() is defined below:
myType foo()
{
myType a = new myType();
...
return a;
}
What happens? Below are 3 alternatives that i can think of so far:
1. assignment be unsuccessful as the local object goes out of scope
once foo() ends
2. assignment is successful (copy ctor) before local object is cleaned
up from memory
3. assignment is successful and "obj" now points to same memory
location as "a"
Thanks and much appreciated.
Sean
I'm a newbie in Java. Was wondering what is the behaviour for the code
below:
myType obj = foo();
where the function foo() is defined below:
myType foo()
{
myType a = new myType();
...
return a;
}
What happens? Below are 3 alternatives that i can think of so far:
1. assignment be unsuccessful as the local object goes out of scope
once foo() ends
2. assignment is successful (copy ctor) before local object is cleaned
up from memory
3. assignment is successful and "obj" now points to same memory
location as "a"
Thanks and much appreciated.
Sean