What is List <?> In Java (Android)?

Possible duplicate:
What is Type <Type> called?
What is List <? > 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 someone explain to me what these two statements mean

 public List<Statements> statements = new ArrayList<Statement.Statements>(); public List<Transaction> transactions = new ArrayList<Transaction>(); 
+6
source share
4 answers

This is Generics in java

List<?> Essentially translates as "List of unknowns", i.e. list of unknown types. ? known as Wildcard (which essentially means the unknown).


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

Essentially, a List is created that accepts only Statement.Statements . Anything outside of Statement.Statements that you want to add to statements will throw a compilation error. The same applies to public List<Transaction> transactions = new ArrayList<Transaction>(); . This means that List limited to the type Statement.Statements (in the statements variable).

+15
source

You must read about Generics to understand this. A list is a raw type, which can be a list of objects such as strings, wrappers, and user-defined objects.

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

The code above says that operators are a reference to the ArrayList of Statement objects. It indicates that the list will contain Statement objects, which are the inner class of the Statement class.

List<?> used to indicate a list of an unknown type.

+2
source

This is the use of generics. You declare a list of Statement objects or Transaction objects.

Check out Wikipedia for more information.

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

+1
source

The statements list can contain only the statements object. It is called Generics. Check it out for custom programs.

http://www.java2s.com/Code/Java/Language-Basics/Asimplegenericclass.htm

+1
source

Source: https://habr.com/ru/post/904647/


All Articles