title: Calling a getter in Java though reflection: What's the fastest way to repeatedly call it (performance and scalability wise)?
body: <p>Given a class <code>Foo</code> and a property <code>bar</code>, <em>neither of which I know at compile time</em>, I need to repeatedly call the getter <code>Foo.getBar()</code> many, many times.</p>
  
  <p>Suppose I have:</p>
  
  <pre><code>Method barGetterMethod = ...; // Don't worry how I got this
  </code></pre>
  
  <p>And I need to do something like this:</p>
  
  <pre><code>for (Object foo : fooList) { // 1000000000 elements in fooList
      Object bar = barGetterMethod.invoke(foo);
      ...
  }
  </code></pre>
  
  <p>The implementation above is still very slow compared to calling it without reflection. Is there a faster way? </p>
  
  <p>What's the fastest way of calling a getter with reflection in Java?</p>