From 79d95ac74eb825d6dbd9c774dbcc3f03489829eb Mon Sep 17 00:00:00 2001
From: Elliott Hughes
On Android, this is a bad idea. Virtual method calls are expensive, -much more so than instance field lookups. It's reasonable to follow +
On Android, this can be a bad idea. Virtual method calls can be more +expensive than instance field lookups. It's reasonable to follow common object-oriented programming practices and have getters and setters -in the public interface, but within a class you should always access +in the public interface, but within a class you might want to access fields directly.
Without a JIT, direct field access is about 3x faster than invoking a -trivial getter. With the JIT (where direct field access is as cheap as -accessing a local), direct field access is about 7x faster than invoking a -trivial getter. This is true in Froyo, but will improve in the future when -the JIT inlines getter methods.
+trivial getter (one that simply returns the value of a field, without +any dereferencing or array indexing). With the Froyo JIT, direct field +access was about 7x faster than invoking a trivial getter. Since +Gingerbread, though, the JIT inlines trivial getter methods, making +that particular optimization obsolete. Manual inlining guided by +profiling can still be a useful technique in general, though.Note that if you're using ProGuard, you can have the best -of both worlds because ProGuard can inline accessors for you.
+of both worlds even with non-trival accessors, because ProGuard can inline +for you.