600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > java string 转对象 将String转换为类对象

java string 转对象 将String转换为类对象

时间:2020-01-27 12:39:29

相关推荐

java string 转对象 将String转换为类对象

I am storing a class object into a string using toString() method. Now, I want to convert the string into that class object.

How to do that? Please help me with source code.

解决方案

I am storing a class object into a string using toString() method. Now, I want to convert the string into that class object.

Your question is ambiguous. It could mean at least two different things, one of which is ... well ... a serious misconception on your part.

If you did this:

SomeClass object = ...

String s = object.toString();

then the answer is that there is no simple way to turn s back into an instance of SomeClass. You couldn do it even if the toString() method gave you one of those funky "SomeClass@xxxxxxxx" strings. (That string does not encode the state of the object, or even a reference to the object. The xxxxxxxx part is

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。