[英]Why can't i pass this array to my target class?
為什么我不能傳遞數組?
for (int a = 0;; a++) {
System.out.print("Enter Name:");
name[a] = in.nextLine();
System.out.print("Enter Age:");
age[a] = in.nextInt();
in.nextLine();
Student student = new Student(name[], age[]);
}
錯誤提示在數組幫助后需要一個.class
如果它接受數組,則取決於您的Student類的構造函數(即,它接受什么)
然后
學生=新學生(姓名,年齡); //在這種情況下,此行應在for循環之后
如果它接受單個名稱和數組
然后
學生人數=新學生(姓名[a],年齡[a]);
為什么我不能傳遞數組?
因為您的語法不正確,所以這里:
Student student = new Student(name[], age[]);
這是原因,傳遞您通常執行的數組
Student student = new Student(name, age);
如果以參數形式引用數組,則可以:
聲明方法
void doSomeTricks(String[] args) {
但要調用/調用您執行的方法
doSomeTricks(myArray);
並不是
doSomeTricks(myArray[]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.