首页 > 解决方案 > 为 GsmCellLocation 类接口返回的 toString 是什么?

问题描述

我试图弄清楚当我调用这个函数 toString() 时返回的是什么。在文档中它说“类 {@code Object} 的 {@code toString} 方法返回一个字符串,该字符串由对象是实例的类的名称、符号字符‘{@code @}’组成,以及对象的哈希码的无符号十六进制表示。返回值如下所示:[22036,36138303,0]

我将包含用于调用函数 to.String() 的代码。我知道 GsmCellLocation 已被弃用,我只是想了解这 3 个数字是什么。一旦我弄清楚这一点,我希望更新到 CellIdentityGsm,谢谢你的帮助。

    @TargetApi(Build.VERSION_CODES.GINGERBREAD)
    @Override
    public void onCellLocationChanged(CellLocation cellLocation) {
        super.onCellLocationChanged(cellLocation);
        if(cellLocation == null) return;
        Log.i(LOG_TAG, "onCellLocationChanged");
        String desc = "\"" + cellLocation.getClass().getSimpleName() + "\" : " + cellLocation.toString();
        textView.setText("Cell Info Logger\nCell Location\n"+desc);
        logger.write(desc);
    } // END onCellLocationChanged

这是它的文档:

    /**
     * Returns a string representation of the object. In general, the
     * {@code toString} method returns a string that
     * "textually represents" this object. The result should
     * be a concise but informative representation that is easy for a
     * person to read.
     * It is recommended that all subclasses override this method.
     * <p>
     * The {@code toString} method for class {@code Object}
     * returns a string consisting of the name of the class of which the
     * object is an instance, the at-sign character `{@code @}', and
     * the unsigned hexadecimal representation of the hash code of the
     * object. In other words, this method returns a string equal to the
     * value of:
     * <blockquote>
     * <pre>
     * getClass().getName() + '@' + Integer.toHexString(hashCode())
     * </pre></blockquote>
     *
     * @return  a string representation of the object.
     */
    public String toString() {
        return getClass().getName() + "@" + Integer.toHexString(hashCode());
    }

标签: javaandroid

解决方案


推荐阅读