【发布时间】:2010-09-13 01:47:13
【问题描述】:
我正在尝试获取一个数组以将可变数量的对象作为输入。我是编程新手,所以我提前道歉。
这是我的代码:
public class Rating{
double [] Ratings;
int CustomerID;
int Domain;
public Rating (int id, int d, double [] x) {
double [] Ratings = x;
int CustomerID=id;
int Domain=d;
}
}
public class All_user{
double [] All_users;
public All_user(Rating...argument) {
double [] All_users={Rating...argument};
}
}
但是,我收到与 double[] All_users={Rating..arguments); 相关的此错误:
Multiple markers at this line
- Syntax error on token "...", . expected
- arguments cannot be resolved or is
not a field
有什么想法吗?提前致谢!
【问题讨论】:
-
变量名应该是 camelCase:Ratings -> Ratings,CustomerID -> customerID(有些更喜欢 customerId)并且你不应该在类名中使用下划线:All_users -> AllUsers。试着习惯它,它会让你的生活更轻松。快速说明:如果参数定义为 Rating... rating (varargs),则参数 rating 是 Ratings[] 的类型。
标签: java arrays object variadic-functions