Search code examples
javaclassequalsinstanceof

is Object instance of MyClass


I need to make equals function for MyClas.

public class MyClass
{
boolean equals(Object value)
  {
    if (... value is type of MyCLass ...)
      {
        return= ... check conditions...;
      } else return false;
  }
}

For this purpose I need to know if value of Object is type of MyClass. How to make it?


Solution

  • In order to check if value is of type MyClass use:

     if( value instanceof MyClass)