Don't remember who but someone here told me once, when I mentioned that I do java now, "wait till you get to reflection..."
Well it's time to suffer

  • 5
    oh, you're doing reflection now! Good luck!

    It's quite easy though. Wait till you get to the Mirror API!
  • 5
    The best tip i got when running into reflection for the first time was "don't"
  • 4
    If you're using reflection at anything other than the framework level, I'd argue it's most likely a case of bad design.

    Reflection isn't hard in and of itself, but it can make code rather hard to reason about (and potentially renders a lot of IDE warnings about unused code etc. useless.)
  • 4
    @AlmondSauce And slow :) Unless cached properly, reflection lookups are not something one should be making in each request.
  • 2
    Usage of reflection nowadays is pretty limited to some very specific cases, often involving DI or specific 3rd party libraries. One of the main reasons it is discouraged is because it often bypasses the OOP design which is the strong suit of Java in the first place.

    As mentiined above I'd refrain from using it unless unavoidable and many problems that are haphazardly solved via reflection should instead be solved with better design.
Add Comment