I'm wrapping a 3rd party library, there is a native library method:
Normally i'd create a wrapper method that accepts a B4A List or Array of GeoPoint objects, and within that wrapper method create a parameterized ArrayList<GeoPoint> to pass to the native library method.
(Working around the fact that a B4A List isn't parameterized).
But as an experiment i instead created a wrapper method that accepts a B4A List and passes that B4A List directly to the native method as the parameterized ArrayList<GeoPoint> parameter:
I tested it with this code:
It works as expected.
OriginPoint and DestinationPoint are GeoPointWrapper objects, the underlying GeoPoint objects are added to the List so WayPoints is an unparameterized ArrayList of GeoPoint objects.
I set a breakpoint and see:
Next i tried this:
The method no longer works, no exceptions are thrown but the method does nothing.
The breakpoint shows:
I then tried this:
The breakpoint shows WayPoints with units of degrees.
Calling GetRoad now throws an exception:
Ignoring the breakpoint showing different units (degrees/micro-degrees) why does the B4A List have a different behaviour depending on how it is Initialized or how items are added to it?
Martin.
B4X:
// native library method
public Road getRoad(ArrayList<GeoPoint> waypoints) {
// method body here
}
Normally i'd create a wrapper method that accepts a B4A List or Array of GeoPoint objects, and within that wrapper method create a parameterized ArrayList<GeoPoint> to pass to the native library method.
(Working around the fact that a B4A List isn't parameterized).
But as an experiment i instead created a wrapper method that accepts a B4A List and passes that B4A List directly to the native method as the parameterized ArrayList<GeoPoint> parameter:
B4X:
// B4A library method
public void GetRoad(ArrayList<GeoPoint> Waypoints) {
// here i call getObject().getRoad(Waypoints)
}
I tested it with this code:
B4X:
Dim WayPoints As List
WayPoints.Initialize
WayPoints.Add(OriginPoint)
WayPoints.Add(DestinationPoint)
OSRMRoadManager1.GetRoad(WayPoints)
It works as expected.
OriginPoint and DestinationPoint are GeoPointWrapper objects, the underlying GeoPoint objects are added to the List so WayPoints is an unparameterized ArrayList of GeoPoint objects.
I set a breakpoint and see:
The GeoPoint can use units of degrees or micro-degrees, the breakpoint shows units of micro-degrees.WayPoints (ArrayList)[52752480,404300,0,52743566,402374,0]
Next i tried this:
B4X:
Dim WayPoints As List
WayPoints.Initialize
WayPoints.AddAll(Array As GeoPoint(OriginPoint, DestinationPoint))
OSRMRoadManager1.GetRoad(WayPoints)
The method no longer works, no exceptions are thrown but the method does nothing.
The breakpoint shows:
The breakpoint now shows units of degrees.WayPoints (ArrayList)[52.752480,0.404300,0,52.743566,0.402374,0]
I then tried this:
B4X:
Dim WayPoints As List
WayPoints.Initialize2(Array As GeoPoint(OriginPoint, DestinationPoint))
OSRMRoadManager1.GetRoad(WayPoints)
The breakpoint shows WayPoints with units of degrees.
Calling GetRoad now throws an exception:
java.lang.ClassCastException: java.util.Arrays$ArrayList
Ignoring the breakpoint showing different units (degrees/micro-degrees) why does the B4A List have a different behaviour depending on how it is Initialized or how items are added to it?
Martin.