Java语法大于/小于:<>他们是特定类别的吗? [英] Java syntax with greater than/less than: <> are they class specific?
问题描述
public class ImageAndTextAdapter extends ArrayAdapter< String> ; {
< String>
a按类型继承的形式?或者是我应该知道的其他一些Java语法?
该类为:
android.widget.ArrayAdapter<字符串>
这就是所谓的泛型 。 <
和>
中的类是类型参数。
这可以通过一个例子来解释:
$ b ArrayList
can存储物品。如果你指定了这样的类型参数: ArrayList< String>
,那么这个数组列表将存储字符串
类型的项(换句话说,它将仅存储 String
s)!
同样, ArrayAdapter
也由一个类型参数化。 ArrayAdapter
可能包含一个值,该值将是<
和<$ c $之间指定的类型c>> ,这在你的情况下是字符串
。
有用的链接:
- 泛型的官方追踪(一个好的起点)
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:
- Official trail on Generics (a good starting point)
这篇关于Java语法大于/小于:<>他们是特定类别的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!