zoukankan      html  css  js  c++  java
  • Equals相等

    /*将父类的equals方法 重写
     * 不改变父类的源代码  equals  比较内存地址
     * 比较两个成员变量 变量值相等  返回true   不等  返回false
     * 重写父类的方法equals  自己定义对象的比较方式
     * */
    public class Person extends Object{
         private String name;
         private int age;
         public Person(){}
         public Person(String name,int age){
             this.name=name;
             this.age=age;
         }
         /*
          * 重写Object的toString()方法    没有必要让用户看到内存地址
          * 要求 :返回值是成员变量的
          * */
     public String toString(){
         return name+":     "+age;
     }
      public boolean equals(Object obj){
          if(this==obj){
              return true;
          }
          //对obj  作非空判断
          if(obj==null){
             return false;
          }
          if(obj instanceof Person){
              //参数obj 接受到的是 Person对象  才能转型
              //对obj这个参数进行向下转型
              Person p =(Person)obj;
              return this.age==p.age;
          }
          return false;
      }

  • 相关阅读:
    Excel—TIME函数简介与用法
    Excel—LEFT、RIGHT、MID函数提取不同位置的字段
    $scope.triggerSave $scope.createForm.dayType.$dirty = false;
    SVN clean up的作用
    js 获取当年到今日的时间区间
    jersey
    vector
    AngularJS 2
    URL 字符介绍
    JS factory
  • 原文地址:https://www.cnblogs.com/lxy4/p/10554497.html
Copyright © 2011-2022 走看看