我正在做研究,其中我发现了以下内容:
假设我有一个类似下面的类,具有以下构造函数:
public class Triangle implements Shape {
public String type;
public String height;
public Triangle(String type) {
super();
this.type = type;
}
public Triangle(String height) {
super();
this.height = height;
}
public Triangle(String type, String height) {
super();
this.type = type;
this.height = height;
}
}
Run Code Online (Sandbox Code Playgroud)
这给了我一个编译时错误.但是,如果我改变height来自String于int一切工作正常.以下是更改的代码:
public class Triangle implements Shape {
public String type;
public int height;
public Triangle(String type) {
super();
this.type = type;
}
public Triangle(int height) {
super(); …Run Code Online (Sandbox Code Playgroud)