Why ArrayList<Crime> and not List<Crime>


#1

I am wondering why the implementation java.util.ArrayList is used rather than the interface java.util.List for the mCrimes member type and return type for the getCrimes() method.

private ArrayList<Crime> mCrimes; public ArrayList<Crime> getCrimes() { ... }

private List<Crime> mCrimes; public List<Crime> getCrimes() { ... }

Kindle location 4049 of 15370


#2

This is a historical Android pattern that we will probably ditch in the future. In older versions of Android, coding to the interface actually resulted in a performance hit, so using ArrayList for the type was preferable to List. This is no longer the case in Gingerbread and later versions of Android, though.