问题是:我有这段代码:
它有效。但是当我尝试创建一个名为AllComponents[10]的Component类数组时,出现了问题。
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]的Component类数组时,出现了问题。
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()无关。这是我的自己写的,它运行良好,我已经检查过。
谢谢!