Is it possible to construct the same object twice?
Sergio Campos J.
Ranch Hand
Joined: Jun 01, 2009
Posts: 53
posted
0
Considere these two lines:
I've thinking of using something like that (in differents moments of the code)
to reset newObject to former values set by constructor in ObjectX class.
Will it work as I think?
"There are times when the easy things should be quick and easy" [...] "and worry about the theory later" -Fred Hamilton-
Even if it *was* legal Java you can't declare the same variable twice. You can assign a value to it twice, but not declare it.
Max Rahder
Ranch Hand
Joined: Nov 06, 2000
Posts: 177
posted
0
To answer your question, there is no built in way to re-initialize an object to its original state. The easiest way would be to create a new instance and throw away (no longer reference) the original object.
And, after you make the code compilable, and take into account that you can't declare the variable twice (but can assign to it twice if you want), you should be clear about exactly what you think it will do. After all, to answer the question "Will it work as I think?" we have to know what you think, and most of us aren't mind readers.
You read his mind. Didn't you?
No doubt. Some of you are truly mind readers.
---o---
Doubts cleared. Thanks to all of you. Especially to Mr. Rahder and Mr. Newton.
New Instance/Throw Away (useful knowledge)
You don't know how much I laughed when I realized what my error was.
I understood there was an error. But I thought it was the word "ObjectX"
in front of the identifier, since I still not sure about when to put/omit it.
What's the meaning of the class name in front of the identifier?
since when we say "= new ObjectX()" we are saying what class it is.
What's the use/effect of putting/omitting the class name in front of the identifier?