zoukankan      html  css  js  c++  java
  • equals()源码

    equals():
    ONE.重写了equal()的类
    1.String
    重写结果,比较的是字符串的内容是否相等
    2.自定义类默认给出的重写方法(Student)
    重写结果,比较自定义类的成员变量是否相同
    TWO.没有重写equal()的类(使用的是object类中的equal方法)
    1.StringBuffer

    two.1.Object类中的equals的实现

        public boolean equals(Object obj) {
            return (this == obj);
        }

    one.1.String类中equls的实现

    public boolean equals(Object anObject) {
            if (this == anObject) {
                return true;
            }
            if (anObject instanceof String) {
                String anotherString = (String)anObject;
                int n = value.length;
                if (n == anotherString.value.length) {
                    char v1[] = value;
                    char v2[] = anotherString.value;
                    int i = 0;
                    while (n-- != 0) {
                        if (v1[i] != v2[i])
                            return false;
                        i++;
                    }
                    return true;
                }
            }
            return false;
        }

    one.2.自定义类默认给出的equals重写方法

    public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass())
                return false;
            Student other = (Student) obj;
            if (age != other.age)
                return false;
            if (name == null) {
                if (other.name != null)
                    return false;
            } else if (!name.equals(other.name))
                return false;
            return true;
        }

  • 相关阅读:
    flask 之定时任务开发
    locust 参数,数据详解
    ab返回结果参数分析
    ab使用命令
    django 实现同一个ip十分钟内只能注册一次(redis版本)
    django开发中利用 缓存文件 进行页面缓存
    django 实现登录时候输入密码错误5次锁定用户十分钟
    django 实现同一个ip十分钟内只能注册一次
    钉钉消息通知机器人python版
    用WMI监控IIS
  • 原文地址:https://www.cnblogs.com/zhuyeshen/p/10955282.html
Copyright © 2011-2022 走看看