• to String()用法


    toString()的使用:
    *
    * 1.java.lang.Object类中toString()定义如下:
    * public String toString() {
    return getClass().getName() + "@" + Integer.toHexString(hashCode());
    }
    *
    * 2. 当我们打印一个对象的引用时,实际上就是调用了其toString()
    *
    * 3. 像String、Date、File、包装类等重写了Object类中的toString(),返回其代表的具体内容
    *
    * 4. 对于自定义类而言,如果我们没有重写Object类中的toString()方法,则返回的仍然是地址值。
    * 如果重写的话,重写的规则:返回当前对象的属性信息。
    //自动生成的equals()
    @Override
    public boolean equals(Object obj) {
    if (this == obj)
    return true;
    if (obj == null)
    return false;
    if (getClass() != obj.getClass())
    return false;
    Customer other = (Customer) 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;
    }

    //手动重写的:重写Object类中的equals()
    // public boolean equals(Object obj) {
    //
    // if(this == obj){
    // return true;
    // }
    //
    // if(obj instanceof Customer){
    //
    // Customer c = (Customer)obj;
    //
    // return this.name.equals(c.name) && this.age == c.age;
    //
    // }
    //
    // return false;
    //
    // }

    //手动重写的toString():
    // @Override
    // public String toString() {
    // return "Customer[name = " + name + ",age = " + age + "]" ;
    // }
    //自动生成toString():
    @Override
    public String toString() {
    return "Customer [name=" + name + ", age=" + age + "]";
    }

    }

  • 相关阅读:
    CAFFE安装(3):cuDNN v4
    监测查询性能(1)
    SQL Server 中的三种分页方式
    使用DBCC SHOW_STATISTICS展示索引的统计信息
    查询表的分配单元数据
    Node.js中的事件
    node-mysql中的连接池代码学习
    Excel动态生成JSON
    使用SignalR实现比特币价格实时刷新
    使用Async同步执行异步函数
  • 原文地址:https://www.cnblogs.com/loushiqiang/p/7252926.html
Copyright © 2020-2023  润新知