2015-12-13 69 views
0

Java的構造方法,我有一個看起來像下面的構造方法:傳遞參數類型列表

public Profile(List<PointGrade> g) 

如果我要調用不同的類,方法,如何傳遞類型列表的說法?

+0

你問如何創建一個列表的實例並填充一些數據? – Keammoort

+0

是的我想創建該類的實例並傳遞參數 –

回答

0
List< PointGrade> g=new ArrayList< PointGrade>(); 

XXX.Profile(g); 
1

你應該創建對象Profile的像這樣的istance:

List<PointGrade> list = new ArrayList<PointGrade>(); 
    Profile profile =new Profile(list); 

而且你也許可以用這個istance這樣的:

 profile.someMethod(); 
0
Profile profile = new Profile(new List<PointGrade>()); 
0

創建的實例列表:

List<PointGrade> list = new ArrayList<PointGrade>(); 

一些數據填充它(如果你不希望傳遞空列表):

PointGrade pg = new PointGrade(); 

//fill PointGrade fields you need 

list.add(pg); 

然後將它傳遞給構造:

Profile profile = new Profile(list);