What is reflection in Java and why is it needed?
Hello colleagues! I'm a beginner Java developer, writing in this language for about six months. Lately I often come across the term "reflection" in documentation and forums. I read several articles but haven't fully grasped the essence. Please explain in simple terms: what kind of beast is this and why is it needed at all?
What confuses me is that in Java we are used to working with classes and objects at compile time: wrote a class, created an instance via new, called a method — everything is clear and predictable. And reflection, as I understand it, allows you to "get inside" a class during program execution. Why might this be needed? After all, if I know the structure of a class, I can write code rigidly.
Please give a concrete example where reflection is indispensable. Let's say there is such a simple class