Android Question Map value is a reference to an object?

elriba

Member
Licensed User
Longtime User
I have a question about Maps. Below is a small excerpt of my class "Customer".

B4X:
'Class = "Customer"
Sub Class_Globals
  Public CustomerID      As String
  Public CompanyName As String
  Public Record As Map                                ' Key=FieldName, Value=FieldObject
End Sub

Public Sub Initialize
   'Initialize the table "record"...
   Record.Initialize
   Record.Put("CustomerID",CustomerID)
   Record.Put("CompanyName",CompanyName)
End Sub

Is the variable "Customer.CustomerId" and the hash key for the first record point to the same variable?

In other words, is
Customer.CustomerId is the same as Record.GetValue("CustomerId")


I am trying, but it doesn't work as expected:

B4X:
' In the activity module....
Sub Globals
    Private Cus As Customer     ' Declare an instance of the class
 End Sub

Sub Activity_Create(FirstTime As Boolean)
    Cus.CustomerId = "Testing..."
 
    MsgBox(Cus.Record.GetValueAt(1))      'Gives an empty string....
End Sub

Maybe I don't understand how maps work...

Thanks for any advice about this...
Edgard
 

MarkusR

Well-Known Member
Licensed User
Longtime User
you can read beginners guide 10 Variables and objects
There are two types of variables: primitives and non-primitives types.
if you assign CustomerID As String it should be a copy
 
Upvote 0

elriba

Member
Licensed User
Longtime User
Hi,
thanks for responding.

If I understand correctly the beginners guide, strings are non-primitive types. In addition, I thought that even assigning a primitive type to a non-primitive type (such as a Map) was a reference assignment. Probably I got the wrong impression.

Edgard
 
Upvote 0
Top