Java use getter in for loop or create a local variable?
<p>I have a for loop which runs 4096 times and it should be as fast as possible. Performance is really important here. Currently I use getter methods inside the loop which just return values or objects from fields which don't change while the loop is in progress.</p>

<p>Example:</p>

<pre><code>for (;;) {
    doSomething(example.getValue());
}
</code></pre>

<p>Is there any overhead using getters? Is it faster using the following way?</p>

<p>Example:</p>

<pre><code>Object object = example.getValue();
for (;;) {
    doSomething(object);
}
</code></pre>

<p>If yes, is that also true for accessing public fields like <code>example.value</code>?</p>

<p>Edit: I don't use <code>System.out.println()</code> inside the loop.</p>

<p>Edit: Some fields are not <code>final</code>. No fields are <code>volatile</code> and no method (getter) is <code>synchronized</code>.</p>