Try
Directions.loadFromWaypoints((Waypoint[])(waypoints.toArray()), opts);
As an alternative
Waypoint[] array = new Waypoint[0];
array = waypoints.toArray(array);
Directions.loadFromWaypoints(array, opts);
Or simply
Waypoint[] array = waypoints.toArray(new Waypoint[0]);
Directions.loadFromWaypoints(array, opts);
See also List#toArray(T[] a).
Addendum: Initially, I thought your cast was a priority issue. A generic parameter Tin List#toArray(T[] a)eliminates the need for an explicit cast, ensuring that the "runtime type of the returned array of the specified array". Essentially, it "acts as a bridge between array-based and collection-based APIs."
source
share