什么是Java(Android)中的List <?>?

Cha*_*har 8 java generics android

可能重复:
什么是类型<Type>被调用?
List <?>在java泛型中的含义是什么?

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>();
}
}
Run Code Online (Sandbox Code Playgroud)

任何人都可以解释这两个陈述的含义

public List<Statements> statements = new ArrayList<Statement.Statements>();

public List<Transaction> transactions = new ArrayList<Transaction>();
Run Code Online (Sandbox Code Playgroud)

Buh*_*ndi 17

这是java中的泛型

List<?>基本上被翻译为"未知数列表",即未知类型的列表.它?被称为通配符(基本上意味着未知).


public List<Statements> statements = new ArrayList<Statement.Statements>();
Run Code Online (Sandbox Code Playgroud)

这基本上创造了一个List只接受的东西Statement.Statements.除了Statement.Statements要添加的内容之外的任何内容statements都将产生编译错误.这同样适用于public List<Transaction> transactions = new ArrayList<Transaction>();.这意味着它List限制为一个类型Statement.Statements(在statements变量上).