I have a class that has a fair amount of static variables, not all of which are initialized to their default values (e.g. I have a boolean I initialize to true, a Set I initialize to a new Set(), etc.). This class is somewhat like a controller, that operates on other classes. After it’s done operating on a class, I’d like to reinitialize all of its static variables to their original values using (if it exists) something that’s a part of the java API, so that I don’t have to make a “reinitializeClassVariables()” method with about a dozen variables in it that would need to be updated every time I make any changes to the static variables declared in the class. Any ideas?
Share
No, nothing build-in. You can do something with reflection or byte code manipulation, but it is not worth and makes all more complicated. Maybe you can refactor the static variables into a new class and then reset with a new instance “when done”.