Linked by Bjorn Raupach on Thu 17th Jul 2008 06:01 UTC
Thread beginning with comment 323465
To read all comments associated with this story, please click here.
To read all comments associated with this story, please click here.
RE: Never programmed in Java before...
by averycfay on Thu 17th Jul 2008 17:13
in reply to "Never programmed in Java before..."
RE[2]: Never programmed in Java before...
by Vanders on Thu 17th Jul 2008 17:30
in reply to "RE: Never programmed in Java before..."
RE[2]: Never programmed in Java before...
by tristan on Thu 17th Jul 2008 17:31
in reply to "RE: Never programmed in Java before..."
"but couldn't you just return an array of pointers to the multiple data values you want to return?
1.) Java doesn't have pointers.
2.) There's no type safety in that approach (meaning it's not a good idea for C++ too) "
My first thought in C++ would be to have a templated ReturnTriple struct along the lines of:
template<class A, class B, class C>
struct ReturnTriple
{
A first;
B second;
C third;
};
which is cheap, type-safe and reusable.
EDIT: Or, as another poster pointed out, just pass parameters by reference. Is this not possible in Java?
Edited 2008-07-17 17:37 UTC
RE[2]: Never programmed in Java before...
by msundman on Thu 17th Jul 2008 18:29
in reply to "RE: Never programmed in Java before..."
RE[2]: Never programmed in Java before...
by IvoLimmen on Thu 17th Jul 2008 20:03
in reply to "RE: Never programmed in Java before..."
1.) Java doesn't have pointers.
Java works with references and a reference is a typed pointer. So if you use Object you kind of are using pointers...
2.) There's no type safety in that approach (meaning it's not a good idea for C++ too)
Exactly: that's why Java made them type-safe.
RE[2]: Never programmed in Java before...
by ebasconp on Thu 17th Jul 2008 20:57
in reply to "RE: Never programmed in Java before..."
1.) Java doesn't have pointers.
Where do you get that assert from???
Everything in Java but the primitive data types are referred via pointers (ok, let's call them "references", but in Java they are the same).
When you declare
MyObject obj = new MyObject();
you are creating an instance of class MyObject and you are assigning a pointer to that instance.
The only difference here is that you cannot do pointer arithmetic (as in C).
RE[2]: Never programmed in Java before...
by Ralf. on Thu 17th Jul 2008 22:14
in reply to "RE: Never programmed in Java before..."







Member since:
2006-01-16
but couldn't you just return an array of pointers to the multiple data values you want to return?