标题: equals()方法中使用getClass()和instanceof方法的区别? [打印本页] 作者: 刘丰伟 时间: 2012-12-27 20:06 标题: equals()方法中使用getClass()和instanceof方法的区别? 还有就是什么时候使用啊,不懂!作者: zjqlovelyy 时间: 2012-12-29 10:53
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.