Android Question [solved]question on "Null"

Discussion in 'Android Questions' started by Maodge, Sep 12, 2018.

Tags:
  1. Maodge

    Maodge Member Licensed User

    pls look at the following code
    Code:
    dim map1 as map
    dim s as string
    dim o as object

        map1.Initialize
        map1.Put(
    "4","d")
        map1.Put(
    "1","a")
        map1.Put(
    "101","a")

    s = map1.get(
    1' s = null
    o = map1.Get(1'o = null

        
    If s<> Null Then
            
    Log("s is not null")
        
    Else
            
    Log("s is null")
        
    End If

        
    If o<> Null Then
            
    Log("o is not null")
        
    Else
            
    Log("o is null")
        
    End If
    run the program, the log shows"
    s is not null
    o is null

    so why first if s<> Null then... prgram judge (s<> Null) = True
    and the second if o<> Null Then... prgram judge (o<> Null) = False ?
    What leads to such result?
    Thanks
     
    Last edited: Sep 12, 2018
  2. Erel

    Erel Administrator Staff Member Licensed User

    "1" is not the same as 1.

    The first key is a string and the second is an int.
     
  3. Maodge

    Maodge Member Licensed User

    thanks.maybe i did not decribe question clear.
    i want know why
    first if s<> Null then... prgram judge (s<> Null) = True
    and the second if o<> Null Then... prgram judge (o<> Null) = False
    the different between s and o -- s is string type and o is object type.
    Did type can effect the result of logic equals?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    I recommend you to check whether the map contains the key with Map.ContainsKey. It is simpler than dealing with nulls.

    The compiler will convert the Null object to "null" string when you assign Null to a string.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice