B4J Question How to cast a IterableList to List?

MathiasM

Active Member
Licensed User
Hello

I want to pass a Map.Values to database.ExecNonQuery2() as second parameter. I thought that should work, because Map.Values resturns a IterableList, but apparently a IterableList and List are 2 different things.

This is my code:
B4X:
db.ExecNonQuery2(query, columnMap.Values)

The error that is being logged is: anywheresoftware.b4a.objects.collections.Map$IterableMap cannot be cast to java.util.List

Is there a way to cast this internally?

I could write a Sub that converts it into a list, but how could I accept a IterableList as argument for my function? This doesn't work:

B4X:
Private Sub CastIterableListToList(iterable As IterableList) As List
   Dim lst As List
   lst.Initialize
   
   For Each s As String In iterable
       lst.Add(s)
   Next
   
   Return lst
End Sub

Thanks!
 
Last edited:

Daestrum

Expert
Licensed User
Longtime User
You just need to pass the map

B4X:
Private Sub CastMapToList(theMap As map) As List
   Dim lst As List
   lst.Initialize
   
   For Each s As object In theMap.Values
       lst.Add(s)
   Next
   
   Return lst
End Sub
 
Upvote 0

MathiasM

Active Member
Licensed User
I'm so retarded, this solution came to my mind a few minutes ago while doing something totally different.
Thanks for thinking with me!
 
Upvote 0
Top