什么是equals方法的默认行为? [英] What is the default behavior of Equals Method?

查看:321
本文介绍了什么是equals方法的默认行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设A是与一些成员X,Y,Z A类:

  A级{
INT X;
INTÿ;
字符串z中;

}

一个是一个对象,因此继承了等于对象中定义的函数。
这是什么功能的默认行为?不会检查成员的平等或者它检查的参考平等?


解决方案

默认实施等于
支持
引用类型 引用相等,和按位平等
值类型
即可。参考平等
表示对象的引用是
相比指代相同的对象。
按位平等意味着进行比较的对象
具有相同的二进制
表示。




< A HREF =htt​​p://msdn.microsoft.com/en-us/library/bsc2ak47.aspx> http://msdn.microsoft.com/en-us/library/bsc2ak47.aspx


Let A be a class with some members as x, y, z:

Class A {
  int x;
  int y;
  String z;
  ...
}

A is an Object so it inherits the "Equals" functions defined in Object. What is the default behavior of this function? Does it check for the equality of members or does it check for reference equality?

解决方案

The default implementation of Equals supports reference equality for reference types, and bitwise equality for value types. Reference equality means the object references that are compared refer to the same object. Bitwise equality means the objects that are compared have the same binary representation.

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

这篇关于什么是equals方法的默认行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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