Map returns null or "null"?

thedesolatesoul

Expert
Licensed User
Longtime User
Hi,
I dont really know if this is a bug or not.
But if I use a key that does not exist with a map it returns a "null" instead of the generic Null.

B4X:
Dim imgFile As String 
imgFile = MimeTypeMap.Get(db.GetFileExt(sft.FilePath))
If imgFile= Null OR imgFile = "null"  Then
   imgFile = MimeTypeMap.Get("default")
End If
 

agraham

Expert
Licensed User
Longtime User
Actually it does return null as you can see here
B4X:
Dim m As Map
   m.Initialize
   Dim s, t As String
   Dim o As Object
   o = m.Get("bill")
   If o = Null Then
       t = "null"
   Else
       t  = "not null"
    End If   
   s = m.Get("fred")
   Msgbox(s & CRLF & t,"")
The java is

B4X:
 //BA.debugLineNum = 19;BA.debugLine="s = m.Get(\"fred\")";
_s = String.valueOf(_m.Get((Object)("fred")));
The Java static valueOf method is documented to return "null" if given a null. I don't know why Erel chose valueOf for string conversions instead of toString.
 
Top