Java语法大于/小于:<>他们是特定类别的吗? [英] Java syntax with greater than/less than: <> are they class specific?

查看:476
本文介绍了Java语法大于/小于:<>他们是特定类别的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这篇关于Java语法大于/小于:&lt;&gt;他们是特定类别的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆