Internal Getter/Setter

Context

Implementation

Affects

Efficiency

Problem

Internal fields are accessed via getters and setters.

But in Android virtual method are expensive.

Refactorings

Direct Field Access

Resolves

Efficiency

Affects

Solution

Consider accessing the fields directly and only use getters and setters in public API.

Taken from the Efficiency Tips:

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.

Links

Related