Re: return more than one object within one method



On 27-5-2005 17:01, Frank Meyer wrote:

Hi newsgroup,

I have a little problem with a method that tries to use another method in
another class.

So far this method receives an ArrayList as follows:

private ArrayList bORead()
    {
        Einl e = new Einl();
WhatTypeIs bO; // ???
bO = e.bocreate();
return bO_OrSomethingElse; // ???
    }
This works fine, but now I would like to also receive an integer created
from the method e.bocreate().

What's the return type of bocreate()? What does the integer represent? (maybe some count of matched items?)

I know that the method bocreate() can only return one object, nevertheless I
found some information about collections that could wrap more than one
object.

Does anyone know if it is possible to receive more than one object (with
different object types) from one method?

That's not possible, a method returns nothing (void), a primitive or an object (possibly null).


However, you can define a new class that holds both, and bocreate() should return an instance of this class.

There are other possibilities too, including the use of a collection class instance, or a 2 element Object array.

Any help is greatly appreciated.

Thanks very much in advance and best regards!

Frank
--
Regards,

Roland de Ruiter
  ___      ___
 /__/ w_/ /__/
/  \ /_/ /  \
.