[英]Java ArrayList get() method doesn't return Point object?
所以我創建了一個Point對象的ArrayList,但是當我使用ArrayList的get()方法時,它似乎沒有返回Point對象。為什么會這樣?
public class SkylineDC {
public static void openAndReadFile(String path,ArrayList pointsList){
//opening of the file
Scanner inputFile=null;
try{
inputFile=new Scanner(new File(path));
}
catch (Exception e1){
try{
inputFile=new Scanner(new File(path+".txt"));
}
catch (Exception e2){
System.out.println("File not found..");
System.exit(1);
}
}
//reading of the file
short listSize=inputFile.nextShort();
pointsList=new ArrayList<Point>(listSize);
//pointsList.add(new Point(10,10));
//System.out.println("Size of List:"+pointsList.size());
pointsList.get(0).
}
public static void main(String[] args) {
String path=args[0];
ArrayList totalPoints=null;
openAndReadFile(path,totalPoints);
//System.out.println("finish");
}
}
ArrayList pointsList
您在聲明中使用了原始類型。
將其更改為ArrayList<Point> pointsList
也:
ArrayList totalPoints=null
也不應該是原始類型。 更改為ArrayList<Point> totalPoints = new ArrayList<>()
我還建議僅讓您的方法返回 List<Point>
而不要嘗試填充現有列表。 我什至不知道您當前擁有的代碼是否會按預期運行。 我懷疑不會。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.