美文网首页
Android Bundle getString方法注意

Android Bundle getString方法注意

作者: 周_0717 | 来源:发表于2020-02-27 23:12 被阅读0次
    /**
     * Returns the value associated with the given key, or null if
     * no mapping of the desired type exists for the given key or a null
     * value is explicitly associated with the key.
     *
     * @param key a String, or null
     * @return a String value, or null
     */
    @Nullable
    public String getString(@Nullable String key) {
        unparcel();
        final Object o = mMap.get(key);
        try {
            return (String) o;
        } catch (ClassCastException e) {
            typeWarning(key, o, "String", e);
            return null;
        }
    }

由于null强转String类型时,会变成“null”字符串,所以只有当转换失败时才会返回null,使用时需要注意对“null”字符串的判断。

2020-02-27

相关文章

网友评论

      本文标题:Android Bundle getString方法注意

      本文链接:https://www.haomeiwen.com/subject/nqxqhhtx.html