• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object type argument?

 
sahar sa
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

thank you in advance,
Sahar.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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é
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any particular reason you want to pass an Object ?
 
Ranveer K Kumar
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
of course you can do by List or Map.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henry Wong
author
Marshal
Pie
Posts: 21008
77
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic