Equals方法如何在对象类中工作 [英] How Equals method works in object class

查看:100
本文介绍了Equals方法如何在对象类中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,
我想知道如何在.net或java中创建object(root class)类.在该方法处理方式中.例如object class具有Equal方法(Equals(object)),此方法确定指定的Object是否等于当前的Object.I不知道如何比较这两个对象.是否有用于比较的dll文件?请清除这个疑问.
谢谢

Hi friends,
i want to know how object(root class) class created in .net or java.In that How methods are processed.For example object class has Equal method(Equals(object)),this method determine whether the specified Object is equal to the current Object.I dont know how it compare these two objects.Is there any dll file for comparision? please clear this doubt.
thank you

推荐答案

默认情况下,Equals方法以以下两种方式之一起作用:

对于值类型,它进行了一些明智的比较:检查两个对象的内容是否相同.
对于引用类型,它将比较引用:如果它们相同,则对象相同,并且无需查看内容.

可以在派生类中重写此行为(例如,String类是一种引用类型,它重写Equals方法以对两个字符串进行逐字节比较).
By default, the Equals method works in one of two ways:

For Value types it does a bit wise comparison: checking if the two object contents are the same.
For Reference types, it compares the references: if they are the same the objects are the same and there is no need to look at the content.

This behaviour can be overridden in derived classes (and is, for example, the String class is a Reference type which overrides the Equals method to do a byte-by-byte comparison of the two strings).


只需查找一下即可:
http://docs. oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#equals%28java.lang.Object%29 [ http://msdn.microsoft.com/en-us/library/bsc2ak47.aspx [ ^ ]

祝你好运!
Just look it up:
http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Object.html#equals%28java.lang.Object%29[^]

http://msdn.microsoft.com/en-us/library/bsc2ak47.aspx[^]

Good luck!


这篇关于Equals方法如何在对象类中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆