首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Java源代码阅览体会(1)-String

2012-08-21 
Java源代码阅读体会(1)-String今天我看到String的源代码,有点迷糊,还请大家不吝赐教。?/*** Compares this

Java源代码阅读体会(1)-String

今天我看到String的源代码,有点迷糊,还请大家不吝赐教。

?

/**     * Compares this string to the specified object.  The result is {@code     * true} if and only if the argument is not {@code null} and is a {@code     * String} object that represents the same sequence of characters as this     * object.     *     * @param  anObject     *         The object to compare this {@code String} against     *     * @return  {@code true} if the given object represents a {@code String}     *          equivalent to this string, {@code false} otherwise     *     * @see  #compareTo(String)     * @see  #equalsIgnoreCase(String)     */    public boolean equals(Object anObject) {if (this == anObject) {    return true;}if (anObject instanceof String) {    String anotherString = (String)anObject;    int n = count;    if (n == anotherString.count) {char v1[] = value;char v2[] = anotherString.value;int i = offset;int j = anotherString.offset;while (n-- != 0) {    if (v1[i++] != v2[j++])return false;}return true;    }}return false;    }
?

这个是String中比较值是否相等的代码,我不明白第一个分支this == anObject,这个在什么时候会成立呢?

热点排行