3
gvnix
6y

God bless reflection.

Comments
  • 0
    @irene i am writing a framework in java and it just makes everything so easy to work with. It's not pretty but it does the job of hiding the complexity from the user.
  • 4
    An old professor of mine once said "If you need reflection, you're doing it wrong."

    I'm inclined to agree in all but a few specialist cases tbh.
  • 1
    @irene oh it's definitely hacky way of doing stuff. But when writing a framework using reflection can make the code actually a lot cleaner but at the cost of making it confusing.
  • 1
    @gvnix What framework are you writing? That's almost never the case in my experience.
  • 3
    @AlmondSauce So its an old application based on swing, I was writing a custom UI framework based on graphs. We can create a BaseUIPanel which may contain various UI elements.

    Now to decouple actual code from listeners attached to these components I wrote another interface IActionTask which actually does the job but this has BaseUIPanel (an interface) as a param, so in this task, we cant extract any value from the UI elements.

    To remedy this (and avoid bad casting), I wrote a method that takes the obj, and field name and returns the object.
Add Comment