File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes myClass.toString - reverse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "myClass.toString - reverse" Watch "myClass.toString - reverse" New topic
Author

myClass.toString - reverse

A Saari
Greenhorn

Joined: Mar 31, 2006
Posts: 26
Hi All

myClass myObject = new myClass();
String s = myObject.toString();

How do I take the String object - s - and get myObject back?


Thanks,
Amy
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
You would have to write your own method to do something like that depending on the specifics of your class. A common method signiture for this type of operation is something like:



Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Rodrigo Alvarez
Ranch Hand

Joined: Apr 10, 2006
Posts: 75
Hi Saari,

In the general case, you can't do such thing. toString() is a one-way conversion.

Your Java object generally contains lot's of info, whereas the toString() is just a String representation which contains much less. And this resulting string as no link with the original object.

To use real world analogy, if your object was a house, toString() would be a picture of that house.


It is a mistake to think you can solve any major problems just with potatoes.<br />--Douglas Adams
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: myClass.toString - reverse