The goal here is to have different implementations of the getList() method return different lists BUT, without writing new classes for each implementation. This way I'd be able get the list I want by writing
The thing of it is tho' is that it doesn't work. Everything compiles fine, so I'm not doing anything "illegal" per se, but I get NullPointerExceptions when the class is initialized and I'm not sure why. Does it have something to do with the static variables being intialized before other stuff? The other idea I had was to write private inner classes that extend Category and have the static variables return new instances of them. It just doesn't seem as "elegant." Anyway - does anyone have any ideas either to get this to work or somethign similar. Thanks!
Brian R. Wainwright
posted 13 years ago
Ok... I should retitle this post "Stupid Developer Tricks. For anyone who cares, this DOES work - what doesn't work is some other code I didn't post.
For future reference, it will help if you include the COMPLETE error message with your posts. By paraphrasing, you lose critical information (such as the file name and line number) that is given with the stack trace for any Java exception. These two pieces of information can help us (or even yourself) track down the cause of the error. So when you have questions in the future, please be sure to include the full stack trace (well, the first dozen lines, or so, at least).