|
Java™ by example!
|
|
|
What is the cost of invoking a method through reflection as opposed to invoking it normally?
First of all, if that method takes a long time to execute, the overhead of invoking it is insignificant. This example program shows some performance differences in milliseconds.
- normal: execute a method normally - same: execute a method through reflection, but use the same method instance - diff: execute a method through reflection, but do a method lookup inside the loop It turns out that looking up the method is rather expensive but invocation is fairly cheap. Main.java:
outputs:
Further Information
Author of answer: Joris Van den Bogaert
Comments to this answer are only viewable by members. Login or become a member!
|
|
|
|
|