I'm working on a program where due to various reasons I only know the name of the class I need at runtime, so I have to use reflection to access it. In one particular place in my program I have to check whether an object is an instance of that class, and as I'm using reflection I can't use instanceof
.
I am storing the object representing the class in a final static field and I am checking if other objects are instances of that class using MY_CLASS.isInstance(obj)
.
However, now I also need to run this check in concurrent manner, meaning that more threads will have access to the MY_CLASS
field. Given that I don't understand exactly how the isInstance
method operates (and I don't think it works the exact same way as instanceof
), I want to know whether this approach is safe to use.
Thank you!
Aucun commentaire:
Enregistrer un commentaire