【发布时间】:2011-01-07 05:51:02
【问题描述】:
问题是:我有这个代码:
public class Component {
public Component() {
// TODO Auto-generated constructor stub
}
public double[] Shifts ;
public double[][] Couplings ;
}
public class Decouplage {
public Decouplage(double[] GroupShifts, double[][] GroupCoup) {
AllComponents = new Component();
AllComponents.Shifts = GetShifts(...blah-blah-bla...);
AllComponents.Couplings = GetGouplings(...blah-blah-bla...);
}
public Component AllComponents ;
}
它有效。 但是当我尝试创建此类组件的数组 AllComponents[10]
public class Decouplage {
public Decouplage(double[] GroupShifts, double[][] GroupCoup) {
AllComponents = new Component()[nComponents]; /////HOW MUST I PUT IN ONE LINE THE NUMBER OF ELEMENTS AND THE () FOR CONSTRUCTOR????
for (int iCounter=0;iCounter<nComponents;iCounter++){
AllComponents.Shifts = GetShifts(...blah-blah-bla...);
AllComponents.Couplings = GetGouplings(...blah-blah-bla...);
}
}
public Component[] AllComponents ;
}
它无法编译。
但是如果我忽略构造函数的 ()
public class Decouplage {
public Decouplage(double[] GroupShifts, double[][] GroupCoup) {
AllComponents = new Component[nComponents]; /////IS IT LEGAL TO IGNORE CONSTRUCTOR, EVEN IF IT IS EMPTY????
for (int iCounter=0;iCounter<nComponents;iCounter++){
AllComponents.Shifts = GetShifts(...blah-blah-bla...);
AllComponents.Couplings = GetGouplings(...blah-blah-bla...);
}
}
public Component[] AllComponents ;
}
它无法将 Shifts 和 Couplings 解析为字段...
你有什么建议? 注意:GetShifts() 与标准 Java 的 getShift() 没有任何区别。这是我自己的,效果很好,我检查了。
谢谢!
【问题讨论】:
-
您不应以大写字母开头的变量命名。请遵守 Java 约定。