lundi 26 juin 2023

Why java.lang.Class doesn't implement java.lang.reflect.Member interface?

I'm working on a Package Browser in browser in Java and trying to write a generic method which can handle all members of the class - basically collecting string representation of them, choosing an image and displaying it in a tree view.

For all Members (Field, Method, Constructor) it has been working great - they all have getName() and isSynthetic() which allows me to treat them in the same way because that's all I need.

But Class is special - even though it has all the methods of that interface, it doesn't technically implement it!.

And to handle it I need a special-case-method or do an instanceof checks, which is not very clean.

So, i guess, this is more of a philosophical question - why is that? Because classes are not considered to be "proper" members of classes and instead are nested? Or because of something else?

Please shine the light on this topic!

I tried to treat objects of type Class<?> as if they implemented interface Member.





Aucun commentaire:

Enregistrer un commentaire