Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java syntax with greater than/less than: <> are they class specific?

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>
like image 353
Craig Millard Avatar asked May 19 '11 19:05

Craig Millard


1 Answers

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 Strings 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:

  • Official trail on Generics (a good starting point)
like image 194
aioobe Avatar answered Oct 01 '22 22:10

aioobe