Listing 11.2: What does 'this' refer to?

Where did ‘get()’ in

mCrimes = CrimeLab.get(this).getCrimes();

come from?

I’ve looked at AbstractList and ArrayList and see the method ‘get(int index)’ that return the element at the index. So what does ‘this’ refer to? What provides ‘this’ integer?

this is a keyword in java that refers to the instance of the current class. In this case, this is inside of an Activity and therefore refers to the Activity instance.

get is a static method on CrimeLab. If it helps, you can navigate to the source of each of those methods in Android Studio by holding down control (or command on a Mac) and clicking on the get method.

cstewart,

You got me on that one. I got so confused looking at the Android site that I completely missed that which I, myself, had typed directly from your book! I see it now. Thanks!