Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How can a REF TO be returned by a Method?

Former Member
0 Kudos

I understand that a OO method can return a value via a RETURNING parameter, but a value only. Now one can also return a REF TO via such a return parameter. But I don't understand that -- if I have to return a value, how/why can I then return a reference to an object?

Thanks in advance for clarification!

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos

I don't understand why you don't understand. Hopefully methods can return a reference, it's so much useful, and used everywhere. A reference is a "value" too (a memory address, more or less). What is the issue with that?

3 REPLIES 3

Sandra_Rossi
Active Contributor
0 Kudos

I don't understand why you don't understand. Hopefully methods can return a reference, it's so much useful, and used everywhere. A reference is a "value" too (a memory address, more or less). What is the issue with that?

0 Kudos

I would second what Sandra said... it's a core concept of object oriented programming.  Objects can have a state but they can also do things and as such methods can return references to other objects that they are composed of or part of.  Anything less than that would require duplication of tons of code for the most menial of tasks because there would be no way to refer to objects that can accomplish a task.

If I were to accept that I may as well go to the car dealership to buy a car and walk out happy that they gave me a VIN number when in reality the purpose is to have the car that can transport me from place to place.

0 Kudos

Fine, I understand that: An object reference is just an address, which is a value as well. But what is the difference then between returning a REF TO an object directly vs. the value of a REF TO an object?