aspose file tools*
The moose likes Beginning Java and the fly likes to get sting value into object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "to get sting value into object" Watch "to get sting value into object" New topic
Author

to get sting value into object

jazy smith
Ranch Hand

Joined: Nov 18, 2009
Posts: 101
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

Joined: Oct 25, 2008
Posts: 2700

I'm confused. Do you want the String to become an Order? Or a property of Order?
Or this:


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

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?

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

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

Joined: Sep 14, 2009
Posts: 1660
    
  11

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?


When you do things right, people won't be sure you've done anything at all.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: to get sting value into object