Object type argument?

Dear friends,
I have to pass many parameters using one argument with data type "object". how can I do this?
how can I pass many parameters just with one Object type argument? can I do somthing with it, like reading one String and then break it to desired section and put it in desired parameters?
or do you have any better idea?

You can create a new class that has fields (with getter and setter methods) for all those parameters. Of course, the receiving method will have to cast the Object to its actual class. It might be better to change the signature of the method so that it uses the actual class.

You can pass many arguments by incorporating them into some sort of data object, but that would not have the type "Object". What would you do it an Object of a different type is passed? You are losing compile-time checking by using "Object" as a parameter type.

Christophe Verré wrote:Is there any particular reason you want to pass an Object ?

Probably because some has written a method with "Object" as its parameter type, not thinking what would be passed.

sahar sa
Ranch Hand

Joined: Jul 06, 2009
Posts: 102

posted Sep 16, 2009 05:47:47

0

Dear friends,
Yes, I want to use a method called creatNewAgent which is as follow:
creatNewAgent(String nickName, String className, Object [] args);
and I need to pass a sort of different types of variables like: Price(double), Strategy(String),Type(String), Utility(double) by arguman args.

1) dear Cristophe yes I have to use this pre-defined method and it needs an Object
2) dear Ritchie I did not understand what you mean exactly? it means that I have to incorporate some sort of data types but still its not an object? so, how can I use it? could you please explain more? I didn't get how can I solve it

thank you so much!
Sahar.

sahar sa
Ranch Hand

Joined: Jul 06, 2009
Posts: 102

posted Oct 04, 2009 01:26:08

0

Dear friend,
Any idea or example would be appreciated, after 20 days I still couldn't solve it. I also face with another method putO2AObject(Object,boolean). Here, also I need to pass a number of different types of variable to this methos as an object(which i dont know how?). I've tried to define a constructor and declare all this variables in that constructor, then make a new isntance of that constructor. But still I dont know how to convert this constructor instance to an object (so it could be passed to PutO2AObject())?
here is the code for:
constructor:

and piece of code which Im using pre-defined putO2AObject class :

but its not working.
any idea would be really appreciat!
Thank you in advance,
Sahar.

Yes, I want to use a method called creatNewAgent which is as follow:
creatNewAgent(String nickName, String className, Object [] args);
and I need to pass a sort of different types of variables like: Price(double), Strategy(String),Type(String), Utility(double) by arguman args.

What have you tried? It seems pretty straightforward to me...

Now, of course, the next issue is... is this what the method expects? Calling it is one thing, but the method needs to know what to do with it too. In other words, it may be a better idea to ask whoever provided this creatNewAgent() method, to explain exactly how to use it.