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 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).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With