【发布时间】:2015-04-22 00:40:38
【问题描述】:
我最近一直在从事一个项目,在该项目中我最终使用了一个扩展另一个类(即连接和传输)的类。我收到的错误是“错误:找不到适合连接的构造函数(无参数)。”错误出现在 Transfer 中构造函数开头的行。
class Connection {
List<Station> connectedStations = new ArrayList();
int length;
boolean isTransfer = false;
public Connection(Station s1, Station s2, int distance) {
/* Code in here */
}
public Connection(Station s1, Station s2) {
/* Code in here */
}
}
和转移:
class Transfer extends Connection {
List<Line> linesTransfer = new ArrayList();
boolean isTransfer = true;
public Transfer(Station s1, Station s2, int distance, Line l1, Line l2) {
/* Code in here */
}
public Transfer(Station s1, Station s2, Line l1, Line l2) {
/* Code in here */
}
}
在我的主课中,我有几个使用这些函数的函数。如果除此功能之外的所有功能都被注释掉,我将继续收到相同的错误:
public static Station findInStations(int iD) {
for(Entry<Integer, Station> stat : stations.entrySet()) {
if(stat.getValue().id == iD) {
return stat.getValue();
}
}
return null;
}
这基本上在主类的实例变量hashmap中找到了你要找的站。
【问题讨论】:
标签: java class constructor