I’ve been doing an Android tutorial and encountered a class with the following:
public class ImageAndTextAdapter extends ArrayAdapter<String> {
Is the <String> a form of inheritance by type? Or is it some other Java syntax that I should know about?
The class is:
android.widget.ArrayAdapter<String>
This is called generics. The class within
<and>is a type parameter.This is easiest explained by an example:
An
ArrayListcan store items. If you specify a type parameter like this:ArrayList<String>then this array list will store items ofStringtype only, (in other words, it will storeStrings only)!Similarly, the
ArrayAdapteris “parameterized” by a type as well. TheArrayAdapterprobably holds a value, and this value will be of the type specified between<and>, which in your case isString.Useful links: