Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Object type argument?

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 74374
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any particular reason you want to pass an Object ?
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
of course you can do by List or Map.
 
Campbell Ritchie
Marshal
Posts: 74374
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 23909
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic