I saw a few topics on SO about this but none really answered my question so here it is:
String s = "a string";
Object o = s;
s = String(o); // EDIT this line was wrong
s = (String)o; // EDIT Corrected line
Now this compiles fine but throws a ClassCastException. The only thing is that I thought there was some way to make this work. is there a way to turn an object such as a string in this case back into the object it once was?
EDIT: Sorry everyone, in my haste I wrote it in incorrectly. I was right about how it actually functions i.e. String(o) but the problem was actually due to me trying to return a wrong object in a method. Very sorry about that. Thanks for confirming that that is how you need to cast though!
Thanks