Reputation: 684
I am using reflection to get certain fields by their names and I'm accessing these fields rather often. Is it good to store the fields in a HashMap<String, Field>
if I found them once and then get them from that HashMap
when I need them again? Or does java do something similar already and this would by totally unneccesary?
Upvotes: 1
Views: 61
Reputation: 418
This is a valid approach as there is no automated "caching" for reflection. As each reflective call consumes time caching on your own is always a good idea.
Upvotes: 1