I wrote a java class which has equals method in it,and in the return type i used two int values (obj1 and obj2 ) these two instances are of int,and when i try to execute this java code i faced the following issue “java equals int cannot be dereferenced” why this int cannot be deferenced error and how can i fix this….
@Override
public boolean equals(Object myobj){
if (null == myobj)return false;
if (this == myobj)return true;
return obj1.equals(that.getAddition()) && obj2.equals(getDiv());
}
I think you’re having a problem because int is a primitive type. And only object are reference types
Either you should use Integer , as in the wrapper class or use == instead of equals. I guess this solves java equals int cannot be dereferenced error.
neha
int is not an object it is a primitive data type and objects are reference type. So instead of equals use == and return obj1 and obj2 separately. hope it solves your problem