Android Question map assignment question

Multiverse app

Active Member
Licensed User
Longtime User
I have a simple question.

B4X:
    Dim mapGlobal As Map
    mapGlobal.Initialize
    mapGlobal.Put("Key1", "Value1")
    map2=mapGlobal

Does the "=" the pass the reference of the mapGlobal to map2 or creates an object at new memory location?
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I have a simple question.

B4X:
    Dim mapGlobal As Map
    mapGlobal.Initialize
    mapGlobal.Put("Key1", "Value1")
    map2=mapGlobal

Does the "=" the pass the reference of the mapGlobal to map2 or creates an object at new memory location?

Can't test it now, but how about altering mapGlobal and see if that change shows in map2?

RBS
 
Upvote 0

Multiverse app

Active Member
Licensed User
Longtime User
Can't test it now, but how about altering mapGlobal and see if that change shows in map2?
Yes, it does

B4X:
    Dim mapGlobal As Map
    mapGlobal.Initialize
    mapGlobal.Put("Key1", "Value1")
    mapGlobal.Put("Key2", "Value2")
    mapGlobal.Put("Key3", "Value3")
    mapGlobal.Put("Key4", "Value4")
   
   
    Dim map2 As Map=mapGlobal
    Log(map2.Remove("Key1"))
   
    Log("mapGlobal: ")
    For i=0 To mapGlobal.Size-1
        Log(mapGlobal.GetKeyAt(i)&", "&mapGlobal.GetValueAt(i))
    Next
   
    Log("map2: ")
    For i=0 To map2.Size-1
        Log(map2.GetKeyAt(i)&", "&map2.GetValueAt(i))
    Next

log:
B4X:
Value1
mapGlobal: 
Key2, Value2
Key3, Value3
Key4, Value4
map2: 
Key2, Value2
Key3, Value3
Key4, Value4
 
Upvote 0
Top