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 ArrayList
can store items. If you specify a type parameter like this: ArrayList<String>
then this array list will store items of String
type only, (in other words, it will store String
s only)!
Similarly, the ArrayAdapter
is "parameterized" by a type as well. The ArrayAdapter
probably holds a value, and this value will be of the type specified between <
and >
, which in your case is String
.
Useful links:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With