Reputation: 23443
From this question, Can two copies of class variable exist?, i was told that multiple instances of the static variable may exist if the class is loaded multiple times, am i able to find out all the occurrences of the "duplicated" classes loaded by the classloader?
Upvotes: 0
Views: 73
Reputation: 8513
Generally speaking, no you cannot. You can get current class loader and tear it apart using reflection (look for classes
field) looking for classes it has already loaded.
That already causes problems, because it assumes you know what's inside the ClassLoader
instance—which is rarely a legitimate assumption.
You can go further up the class loader tree using getParent()
and dig for classes
in parents. What you cannot do though, is find all the class loaders—you can go up the tree, but not down the tree. The problem is, you are rarely interested in the parent class loaders—siblings are of interest.
Upvotes: 3
Reputation: 2494
Go back and follow the links on the question, there are quite a few other question and answers combos that I think explain it, but basically I think different static instances can exist if the class is loaded by different class loaders, they will more then likely be completely seperate from each other, so for what you are asking you can not have duplicated instances
EDIT: specifically this one is it possible to have multiple instances of static variables
Upvotes: 0