A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

还有就是什么时候使用啊,不懂!

1 个回复

倒序浏览
The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).
这是文档里面equals方法的说明,也就是说如果引用同一个对象的时候为true,否则为false。

下面这个是getClass的文档里面说明。
Returns the runtime class of this Object. The returned Class object is the object that is locked by static synchronized methods of the represented class.
  1. class Demo
  2. {
  3.         void Show(){System.out.println(1);}
  4. }

  5. class Ins extends Demo
  6. {
  7.         void Method(){System.out.println(2);}
  8. }

  9. class Demo2
  10. {
  11.         public static void main(String []args)
  12.         {
  13.                 Ins ins = new Ins();
  14.                 Demo demo = new Demo();
  15.                 Object obj = new Object();
  16.                 Demo demo2 = new Demo();
  17.                 Demo demo3 = demo2;
  18.                 System.out.println(demo instanceof Ins);
  19.                 System.out.println(demo.equals(ins));
  20.                 System.out.println(demo instanceof Object);
  21.                 System.out.println(demo.equals(obj));
  22.                 System.out.println(demo.getClass()==obj.getClass());
  23.                 System.out.println(demo2.getClass()==demo.getClass());
  24.                 //System.out.println(demo2.==demo3);
  25.                
  26.         }
  27. }
复制代码

未命名.jpg (10.38 KB, 下载次数: 25)

未命名.jpg
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马