JavaSE11(1)采用类

object

equals

 1 package LS_11;
 2 
 3 public class TestObject {
 4     public static void main(String[] args) {
 5         Object object = new Object();
 6         Object object2 = new Object();
 7         System.out.println(object);
 8         //equals比较还是==
 9         System.out.println(object.equals(object2));
10 
11         TestObject obj = new TestObject();
12         TestObject obj2 = new TestObject();
13         System.out.println(obj == obj2);
14         System.out.println(obj.equals(obj2));
15         //直接打印对象默认会调用toString()方法
16         System.out.println(obj);
17         System.out.println(obj.toString());
18 
19         //输出哈希值
20         System.out.println(obj.hashCode());
21     }
22 }
Object类

 

关于equals

 

posted @ 2021-01-23 18:53  赚钱买个打印机  阅读(43)  评论(0编辑  收藏  举报