Why does Method access seem faster than Field access?
I was doing some tests to find out what the speed differences are between using getters/setters and direct field access. I wrote a simple benchmark application like this: public class FieldTest { private int value = 0; public void setValue(int value) { this.value = value; } public int getValue() { return this.value; } public static void doTest(int num) { FieldTest f = new FieldTest(); // test direct field access long start1 = System.nanoTime(); for (int i = 0; i < num; i++) { f.value = f.value + 1; } f.value = 0; long diff1 = System.nanoTime() - start1; // test method field access long start2