B4J Question CreateThreadSafeMap

LucaMs

Expert
Licensed User
Longtime User
Although I assume the answer is "Yes", I am not absolutely sure.

The following source is correct, right?
B4X:
    Dim mapParent As Map
    mapParent = srvr.CreateThreadSafeMap
 
    Dim mapChild1 As Map
    mapChild1 = srvr.CreateThreadSafeMap
 
    Dim mapChild2 As Map
    mapChild2 = srvr.CreateThreadSafeMap
 
    mapParent.Put("Child1", mapChild1)
    mapParent.Put("Child2", mapChild2)
I mean that the child Maps must also be created that way and they will be safe.
(srvr is a jServer server, of course).

---------------------------------------------------------------------------------------

A doubt that came to me while I was writing this post: if the mapMain has been declared as Public, must the children be as well or can/must they be declared as Private?
(I will verify this personally shortly, perhaps using "normal" Maps).
EDIT:
I did a test (not server and therefore not CreatetThreadSafeMap):
I have declared mapMain as Public in the B4XMainPage.
Then I declared, initialized and filled the child Maps in a private Sub of the B4XMainPage; I declared them using Private and not Dim, although it is the same thing there.
Well, the two child Maps (and their content) are accessible from a second B4XPage.
 
Last edited:

agraham

Expert
Licensed User
Longtime User
It is only the variables themselves that are Public or Private, and it is the compiler that enforces that. At runtime all references are equal as the visibility does not carry through to the compiled code. Once you put an object value or reference in an Array or Map or pass it to a Sub it is always visible.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
It is only the variables themselves that are Public or Private, and it is the compiler that enforces that. At runtime all references are equal as the visibility does not carry through to the compiled code. Once you put an object value or reference in an Array or Map or pass it to a Sub it is always visible.
Thanks.

The question is the first, placed before the dotted line. The other doubt came to my mind while I was writing that one (and I shouldn't have written it, as it can be misleading).
 
Upvote 0
Top