B4J Question [BANano] [SOLVED] Map.IsInitialized Inclusion on map keys


Licensed User
Longtime User
Hi there

I was just cleaning my project and removed all .clear methods for my maps as I noted in the transpiled code that clearing them was not necessary due to to .initialize method just after 'dim m as map', thing is this has resulted in something else.

This is what happens...

When maps are defined with CreateMap, everything is well. The issue is when a map is dimmed, initialized and then put statements are used. Whilst CreateMap returns an undefined '.isinitialized' value for the map, dimming a map, then calling .initialize and then .put, results in a true '.isinitialized' value, which is also included as part of the map keys and values.

Case 1

Dim nm As Map = CreateMap("a": "a", "b": "b", "c": "c")
    Log (nm.IsInitialized)

This returns 'undefined' on the log for .isinitialized

Case 2

Dim nm As Map
    nm.Put("a", "a")
    nm.Put("b", "b")
    nm.Put("c", "c")

This returns 'true' on the log for .isinitialized, however '.isinitialized' is added to the map size and thus on .GetKeyAt and .GetValueAt as 'isinitialized' and 'true' respectively, i.e. part of the .Keys value


Having .Clear just after .Initialize ensures that .isinitialize does not exist and is 'undefined' in Case 2, this is the solution in my case, but perhaps something to look at?


  • BANanoExplorer.zip
    1.1 KB · Views: 301