Bug? Bug with List.Initialize2 ?

Informatix

Expert
Licensed User
Longtime User
I thought this code:
B4X:
Dim ListeTas As List
ListeTas.Initialize2(Array As Int(0, 1, 2, 3))
...was similar to that one:
B4X:
Dim ListeTas As List
ListeTas.Initialize
For i = 0 To 3
   ListeTas.Add(i)
Next
...but it seems it's not the case because the first case returns an error (Unsupported Operation Exception) when I try to remove the first element (ListeTas.RemoveAt(0)).
 

agraham

Expert
Licensed User
Longtime User
I don't know why Erel designed it this way, I think he might have been trying to make the Array and Lisr APIs similar.

Initialize sets the internal object to a Java ArrayList whereas Initialize2 sets it to a Java Arrays.asList(Object[]) which returns a fixed size List which is not an actual Java List but an internal type of List. I did at one time check its actual type, but I've forgotten what it is now.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…