什么是表&LT;&GT;在Java中(Android版)? [英] What is List<?> in Java (Android)?
问题描述
可能重复:结果
是什么类型&lt;&型GT;叫什么名字?结果
什么名单&LT;&GT;意味着Java泛型?
块引用>包com.xyz.pckgeName;进口的java.util.ArrayList;
进口的java.util.List;公共类声明{//公共字符串
公共字符串状态;
公共字符串USER_ID;
公共字符串名称;
公共字符串available_balance;
公共字符串CURRENT_BALANCE;
公共字符串credit_card_type;
公共字符串bank_id;
公开名单&LT;发言与GT;声明=新的ArrayList&LT; Statement.Statements&GT;();公共类声明{
公共字符串月;
公共字符串ACCOUNT_ID;
公共字符串USER_ID;
公共字符串ID;
公开名单&LT;&交易GT;交易=新的ArrayList&LT;&交易GT;();
}
}任何人能解释我是什么这两个语句的意思
公开名单&LT;发言与GT;声明=新的ArrayList&LT; Statement.Statements&GT;();公开名单&LT;&交易GT;交易=新的ArrayList&LT;&交易GT;();
解决方案
列表&LT;&GT;
基本上转化为的未知列表的,即未知类型的列表。在被称为一个通配符一>(这基本上是指的未知的)。
公开名单&LT;发言与GT;声明=新的ArrayList&LT; Statement.Statements&GT;();
这基本上是创建一个
列表
只接受Statement.Statements
。要添加到语句
将创建一个编译错误。这同样适用于Statement.Statements
之外的任何公开名单&LT;&交易GT;交易=新的ArrayList&LT;&交易GT;();
。这意味着列表
一>到类型Statement.Statements
(在语句
变量)。Possible Duplicate:
What is Type<Type> called?
What does List<?> mean in java generics?
package com.xyz.pckgeName; import java.util.ArrayList; import java.util.List; public class Statement { // public String public String status; public String user_id; public String name; public String available_balance; public String current_balance; public String credit_card_type; public String bank_id; public List<Statements> statements = new ArrayList<Statement.Statements>(); public class Statements { public String month; public String account_id; public String user_id; public String id; public List<Transaction> transactions = new ArrayList<Transaction>(); } }
Can anyone explain me what these two statements mean
public List<Statements> statements = new ArrayList<Statement.Statements>(); public List<Transaction> transactions = new ArrayList<Transaction>();
解决方案This is Generics in java
List<?>
is essentially translated as a "List of unknowns", i.e., a list of unknown types. The?
is known as a Wildcard (which essentially means unknown).
public List<Statements> statements = new ArrayList<Statement.Statements>();
This essentially creates a
List
that only acceptsStatement.Statements
. Anything outside ofStatement.Statements
that you want to add tostatements
will create a compilation error. The same applies topublic List<Transaction> transactions = new ArrayList<Transaction>();
. This means that theList
is bounded to a typeStatement.Statements
(onstatements
variable).这篇关于什么是表&LT;&GT;在Java中(Android版)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!