Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

to get sting value into object

 
jazy smith
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have one String 'DETAILS' and I want to pass this string as Order class' object. i.e.



how can I pass 'DETAILS' to the getOrder method ?
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm confused. Do you want the String to become an Order? Or a property of Order?
Or this:
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's hard to answer this question, because we don't know what your Order and WestOrder classes look like, and what the DETAILS string contains. A String is a totally different kind of object than an Order or a WestOrder. It sounds like this:


Trying to fit a square peg in a round hole

There is no generic way to pass a String to a method that takes a different kind of object. Does the DETAILS string contain information on an order? What does it look like? Maybe you need to parse the string, make an Order object and set the fields of that object using information found in the string?
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you'll need a constructor/method that accepts a String and returns a WestOrder

But I would really recommend you to read some tutorials about object orientation and java.
 
Janeice DelVecchio
Saloon Keeper
Posts: 1809
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
uhm.... why not just add an additional parameter? Ahh I guess it doesn't matter.

What you need to do is first associate the string with the WestOrder. Something like this (and forgive me cause I don't have a lot of your code to work with):



Then when you send the WestOrder to the setOrder, you can get the details out like this:



Does that help?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic