I have been trying to accomplish this for a while now, and there seems to be on easy way to accomplish it.
I have a class
Instances of this class may be loaded by seperate class loaders. The requirement is that no matter what classloader its loaded from, the instances are equal if the IDs are equal.
I have not found a good way to perform this comparison. The only way I have found so far is to serialize the instances into the same classloader, and perform the comparison there.
Alternately I could compare the class name. But classes could have the same name and be loaded from different library files. I suppose this is unavoidable since the only difference in this case IS the classloader possibly. I also found that its probably sensible to use some special technique to compare the SerialVersionID of the class too. Which I can do.
The bottom line is that I seem to be relegated to comparying class name, SerialVersionID, and the ID variable of the class. This is the only way without serializing the class.
Hmm, perhaps I could look at comparator interface?
Thats a novel idea, I didnt think about enums. I'm familiar with the techniques. However, they won't work here. The comparison already works when the class I have is in the same classloader. The problem is it fails when the classes are in seperate classloaders. So does their technique. Not only that, they bail calling it too much work and probably unnecessary
ahh well. ILl just have to serialize before I compare.
Can't you load the class in a higher classloader so each section sees the same version of the loaded class? The other option is the 'Jini solution', where you can parse for and test the ID without deserialising the stream, but that's probably more effort than it's worth unless you do it a billion times a day.