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?
Share
Generally speaking, no you cannot. You can get current class loader and tear it apart using reflection (look for
classesfield) looking for classes it has already loaded.That already causes problems, because it assumes you know what’s inside the
ClassLoaderinstance—which is rarely a legitimate assumption.You can go further up the class loader tree using
getParent()and dig forclassesin 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.