this kind of code happens to me all the time:<br><br><FONT FACE=monospace>MyAbstractClass objectName;<br>try {<br> objectName = somethingThatNeedsToBeInTryBlock;<br>} catch (Throwable t) {<br> System.err.println("Error: <" + t.getMessage() + ">"<br> t.printStackTrace(Trace.toPrintStream());<br>}<br>Object o = objectName.returnObject();</font><br><br>this is about as generic as I can get. This obviously won't work because <FONT FACE=monospace>objectName</font> may not have been initialized, and you can't instantiate it because it's an object of an abstract class. So... what's the workaround for this? I know and you know that this object has been initialized, but seeing as how we're outside of the try block, Java doesn't know it. How can we either (a) instantiate the object (and I'm not creating a temporary object of type <FONT FACE=monospace>MyAbstractClass</font> just for the purposes of avoiding the error message if I can help it) or (b) get Java to know that it's already been instantiated? Like, this line of code (the one that deals with the already-initialized object) CAN NOT (beyond Java's shadow of a doubt) be executed unless the try() block is successful? And assume that I can't just throw all everything below the try block inside of the try block- that's just bad. Especially since I'm doing recursion, and I'm NOT calling recursion from inside of a try block. Eh Hmm. *cough cough, hack hack*<br><br>So... can anybody help me out? I've run into this problem so many times (just about every time I deal with try blocks and abstract classes in the same scope), I'm willing to give a vote (2 if I can help it! I'll figure out a way, I promise!) for TipMaster of the Week to whoever comes up with the best answer. (Gah, I'm running a contest on somebody else's website, I should be shot. I hope the admins don't kick me off. NOTE: I am not running a contest.) And by "best answer", I mean, best answer- I guess I could ship this code off to those bug fixer guys, but I guess I already knew that. Neat idea, but I think company-confidential code or anything that resembles it has to stay out of other companies' hands (hence the word confidential, I guess). So.. can somebody PLEASE give me a hand? This problem (or at least this type of problem) has been bugging me for months, and it's really a pain to work around it for specific examples. Thank you so much (so much you wouldn't believe it!) to whoever can help me.<br><br>Thanks again (and again and again and again after you help me). NOTE: If all I can do is create a temporary object of the abstract class and you're the guy who tells me something I really didn't want to know, you're getting nada for TipMaster of the Week votes. Kill the messenger. But if it really is all I can do (and you're sure about this), please tell me, don't hold back. Thanks (yet) again.<br> <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence."
light the world, and bring depth to the silence."