I use the advice suggested by Joshua Bloch Effective Java, Item 52: Refer to objects by their interfaces .
However, most code examples have Android, I understand that the following code is pretty common.
private ArrayList<Integer> mPhotos = new ArrayList<Integer>();
I understand that this is due to optimizing performance, as the following code will be slower.
private List<Integer> mPhotos = new ArrayList<Integer>();
However, is there such an optimization technique? As if I read from http://developer.android.com/guide/practices/design/performance.html
On devices without JIT, it is true that calling methods using a variable with the exact type rather than an interface is somewhat more efficient. (So, for example, it was cheaper to call methods on a HashMap map than a Map, although in both cases the map was a HashMap.) It wasn’t that it was 2 times slower; the actual difference was more like 6% slower. In addition, JIT makes two virtually indistinguishable.
Should we assume that our devices do not have JIT, and refer to objects without interfaces? Or, will we just take the advice of Joshua Bloch?
source share