我有一个带有默认构造函数和参数化构造函数的类,如下所示,
public class Input {
private String max;
public Input() {
}
public Input(Input sourceInput) {
this();
this.max = sourceInput.getMax();
}
@XmlAttribute(name = "max")
public String getMax() {
return max;
}
public void setMax(String max) {
this.max = max;
}
}
我正在像下面那样实例化输入,
Input original = new Input();
original.setMax("20");
Input copy = new Input(original);
此代码在Eclipse中编译良好。但是,当我使用Maven编译此代码时,Maven编译器插件为我提供了Input copy = new Input(original);
constructor Input in class Input cannot be applied to given types;
required: no arguments
found: ipm.calc.bridge.api.xsd.definition.Input
reason: actual and formal argument lists differ in length
您能告诉我这段代码有什么问题吗? 创建第二个构造函数以获得相同对象的副本。 我已经为eclipse和Maven都配置了Java 8。 (这里的Maven表示我没有在Eclipse之外安装过集成的Eclipse)
答案 0 :(得分:1)
Input original = new Input();
original.setMin("10");
original.setMax("20");
Input copy = new Input(input);
新输入(输入)中的输入在哪里。您应该传递原始而不是将输入传递给构造函数,它应如下所示
Input copy = new Input(original);