The base class does not override the reference type of the Object. Equals method to implement Equals.
Source: Internet
Author: User
/// ==++ ==//// Copyright (c) OwnCom Corporation. all rights reserved. //// = -- =/* = ========================================================== ========== ***** Class: myRefType ***** Purpose: the Object is not overwritten for the base class. equals ***** ==================================== ========================================================== ========= */class MyRefType: baseType {RefType retObj; // This field is a reference type ValueType: valObj; // This field is a value type publi C overide boolean Equals (object obj) {// if the base class has implemented the Equals method // first let the base type compare the fields in it // if (! Base. equals (obj) return false; // if obj is null, if (obj = null) return false; // if the types of the two objects are different, if (this. getType ()! = Obj. GetType () return false; // convert obj to a defined type to access its field. // Note that the transformation here will not fail, because it is known that it is the same type MyRefType other = (MyRefType) obj; // compare the reference type field if (! Object. Equals (refObj, other. refObj) return false; // compare the value type fields, use the Equals method of this field type if (! Valobj. Equals (other. valobj) return false; return true;} // reload = and! = Operator public static boolean operator = (MyRefType o1, MyRefType o2) {return Object. Equals (o1, o2);} public static boolean operator! = (MyRefType o2, MyRefType o2) {return! (O1 = o2 );}}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.