我在Groovy中有以下代码违反了我的逻辑:
HashMap<Integer,NLevelDynamicAlias> nLevelAliases = new ArrayList<>();
这实际上是一个错字。但是代码运行良好,直到我将代码复制到Java方法之前,我才意识到它。
Groovy如何使其工作?那是强制的一部分吗?
答案 0 :(得分:0)
时髦的“魔术”))
尝试此代码:
func navigation(_ navigation: SYNavigation, didUpdate positionInfo: SYPositionInfo?) {
if (mapRoute != nil){
mapView.remove(mapRoute)
computeRoute(from: startPointMP, to: endPointMP)
}
}
func computeRoute(from fromCoordinate: SYGeoCoordinate, to toCoordinate:
SYGeoCoordinate) {
let startWaypoint = SYWaypoint(position: fromCoordinate, type: .start, name: "Begin")
let endWaypoint = SYWaypoint(position: toCoordinate, type: .end, name: "End")
let routingOptions = SYRoutingOptions()
routingOptions.transportMode = .unknown// For other options see SYTransportMode
routingOptions.routingType = .economic// For other options see SYRoutingType
routing.computeRoute(startWaypoint, to: endWaypoint, via: nil, with: routingOptions)
}
func routing(_ routing: SYRouting, didComputePrimaryRoute route: SYRoute?) {
SYNavigation.shared().start(with: route)
// You might want to put it also on the map
mapRoute = SYMapRoute(route: route!, type: .primary)
markerEnd = SYMapMarker(coordinate: endPointMP!, image: UIImage(named: "Arrive")!)
mapView.add(mapRoute)
mapView.add(markerEnd)
mapView.add(markerStart)
mapView.cameraMovementMode = .free
}
您会收到一个错误:
...由于:groovy.lang.GroovyRuntimeException: 找不到与以下对象匹配的构造函数:java.util.HashMap(java.lang.Integer,java.lang.Integer,java.lang.Integer)
意味着groovy尝试使用左侧的ArrayList中指定的参数在左侧查找类型的构造函数