Hi all,
I often use maps (with readMap and writeMap) to load and save data.
However, I just noticed that if I save a boolean value to a map:
...and load it later with:
...it appears to work:
...but when I test it, it fails:
It only seems to work if I explicitly cast it to a boolean:
I found this confusing, thinking at first that there must be implicit casting happening. The "put" seemed to implicitly cast True to "true", and the "get" returned "true" (no surprise) but the expression didn't implicitly cast "true" to True.
I wonder if this is one of those where I should write the known type first in the expression?
I'm guessing this may trip up others, so I hope this helps.
I often use maps (with readMap and writeMap) to load and save data.
However, I just noticed that if I save a boolean value to a map:
B4X:
settingsMap.Put("sound", True)
...and load it later with:
B4X:
settingsMap.Get("sound")
...it appears to work:
B4X:
Log("sound = " & settingsMap.Get("sound")) 'returns "sound = true"
...but when I test it, it fails:
B4X:
If settingsMap.Get("sound") = True Then 'returns false
It only seems to work if I explicitly cast it to a boolean:
B4X:
If settingsMap.Get("sound").As(Boolean) = True Then 'returns true as intended
I found this confusing, thinking at first that there must be implicit casting happening. The "put" seemed to implicitly cast True to "true", and the "get" returned "true" (no surprise) but the expression didn't implicitly cast "true" to True.
I wonder if this is one of those where I should write the known type first in the expression?
B4X:
If True = settingsMap.Get("sound") Then
I'm guessing this may trip up others, so I hope this helps.
Last edited: