0

The project I am currently working on uses reflection to lookup beans and inject them into corresponding injection points. The project is also built on Spring. For some reason it has been bugging me to see all the reflection for a while.

Then I thought how about using org.openide.filesystems to represent the injections and injection points in an xml file which gets generated by AnnotationProcessors at compile time. This xml file could be loaded at runtime and all the dependencies injected at appropriate injection points.

While I know that I can just create an example implementation, I am afraid that I might be just trying reinvent the wheel, so I decided to post the question here. Why is that nobody objects to use and abuse of spring and reflection in Web Projects ?

ShaggyInjun
  • 2,880
  • 2
  • 31
  • 52
  • 2
    Why would they complain? Reflection saves development time. If the application meets the performance requirements then why spend more time than necessary to develop it? I don't question whether my 3rd party libraries achieve their goals in the most efficient way possible as long as they achieve them in a fast enough and useful way. – Pace Aug 29 '14 at 19:54
  • Well, you are talking from an end user perspective. My question was about framework devs and why the concept I mentioned above hasn't gained more attention / momentum. I mean, it has come to my mind and that usually means everybody else has basically discarded that idea. So I wonder why they have discarded it. The end users will most definitely use a framework that is more efficient than one that uses reflection. http://stackoverflow.com/questions/435553/java-reflection-performance – ShaggyInjun Aug 29 '14 at 20:03
  • What makes you think that file I/O is going to be faster than reflection? Reading from the disk is another notoriously slow process. Furthermore, how would you avoid reflection? If you've read in the file and you know that a class named "foo" has a property named "bar" and that property needs to be set to 5 then you still need to use reflection to set the property. Perhaps your approach is faster. The short answer is that Spring is popular because it was first. When Spring started dependency injection didn't exist (except as science projects). Now it's popular because it's popular. – Pace Aug 29 '14 at 20:12
  • Oh, we take the hit caused by I/O during startup, so it doesn't affect the actual request processing. Typical [layer.xml](http://netbeans.dzone.com/tips/play-with-xml-layer) file where the dependencies are declared takes in full path to the classes. Beyond this point I am not entirely sure if netbeans indeed uses reflection to lookup and instantiate those classes, but I doubt it based on my work with the netbeans platform for nearly 2 years. But even if it does, the framework would hide away the reflection calls therefore discouraging use and abuse of `reflection`. – ShaggyInjun Aug 29 '14 at 20:25
  • Yeah, I get the spring was here first, but that has never stopped technology to improve in the past, so my question still stands IMO. Why didn't the approach above entice java web framework developers. – ShaggyInjun Aug 29 '14 at 20:26
  • The reflection hit in Spring for looking up beans and injecting them is also only at startup...so if you get to ignore the I/O hit at startup then you get to ignore the reflection hit at startup. Therefore they have the same performance. – Pace Aug 29 '14 at 20:27
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/60262/discussion-between-shaggyinjun-and-pace). – ShaggyInjun Aug 29 '14 at 20:28

0 Answers0