我正在尝试返回包含在特定站点开始或结束的网络中的连接的集合。我无法弄清楚如何返回它并获取工作站参数。还有正确的方法在方法中创建hashMap,还是应该在它之外创建?
它给出了返回语句
的错误incompatible types: Connection cannot be converted to Collection<Connection>
CODE:
/**
* Return a Collection containing all the Connections in the network that
* start or end at a specified station
*
* @param station Station to/from which the Connection should run
*
* @return a Collection containing all the connections that start or end at
* the specified station
*/
@Override
public Collection<Connection> getConnectionsFrom(Station station) {
Map<Station, Connection> stationConnectionFrom = new HashMap<Station, Connection>();
return stationConnectionFrom.get(station);
}
答案 0 :(得分:1)
如果您无法更改方法签名,则可以执行以下操作:
User