devxlogo

Override equal() and clone() a Method of an Object

Override equal() and clone() a Method of an Object

This a very secure and unique way to override equal() and clone() a method of an object.

class MyClass {    	public boolean equals(MyClass o)	{		boolean retVal = false;		if(o == null)			return retVal;		if(	!(o instanceof MyClass))			return retVal;		try		{			java.lang.reflect.Field[] thisF = getClass().getDeclaredFields();			java.lang.reflect.Field[] compareF = o.getClass().getDeclaredFields();			retVal=true;			for(int i = 0; i 

devx-admin

Share the Post: