Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is List<?> in Java (Android)? [duplicate]

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>();
like image 784
Chatar Veer Suthar Avatar asked Dec 29 '11 07:12

Chatar Veer Suthar


2 Answers

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 accepts Statement.Statements. Anything outside of Statement.Statements that you want to add to statements will create a compilation error. The same applies to public List<Transaction> transactions = new ArrayList<Transaction>();. This means that the List is bounded to a type Statement.Statements (on statements variable).

like image 85
Buhake Sindi Avatar answered Sep 27 '22 21:09

Buhake Sindi


It is the use of generics. You are declaring a List of either Statement objects or Transaction objects.

Check out wikipedia for more info

http://en.wikipedia.org/wiki/Generics_in_Java

like image 32
nmjohn Avatar answered Sep 27 '22 19:09

nmjohn