Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
gvnix19336y@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.
-
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. -
gvnix19336y@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.
-
@gvnix What framework are you writing? That's almost never the case in my experience.
-
gvnix19336y@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.
God bless reflection.
rant