vendredi 5 octobre 2018

Java reflection, a valid solution in this case?

So I read a lot about reflection. I decided to not use reflection in some specific cases in my new Project anymore. After my last question. But when I removed some reflection, I came to my JPA-relation-processor, it hurts that much ... that I have to ask another question, because I got so much negative feedback about reflection.

I have about 100 Entities. Each has some JPA-relations. Well I have a service for each entity. The "problem" is, that I have to write at least four specific methods for each entity in this service, to map it to a model and back (setting attributes and so on). Well first it's a lot of work in my opinion to create all this specific methods and keep them updated. But I'm more worried about, that not each mapper/method is written the same way, which reflection guarantees. So in my opinion it is worth to use reflection in this specific case. My problem is that I have limited resources and in my opinion I can save so much time with reflection. What do you think about it, would you still not recommend it to use it in just this specific case? Thank you!

I wrote some (really simple) performance tests and couldn't find a big difference in execution time, when I use it rarely.





Aucun commentaire:

Enregistrer un commentaire