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

前端 未结 4 2015
萌比男神i
萌比男神i 2021-01-01 18:20

I\'ve been doing an Android tutorial and encountered a class with the following:

public class ImageAndTextAdapter extends ArrayAdapter {
         


        
4条回答
  •  感动是毒
    2021-01-01 18:37

    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 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)

提交回复
热议问题