Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 550
vico Avatar asked Jan 13 '23 12:01

vico


2 Answers

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

 if( value instanceof MyClass) 
like image 132
BobTheBuilder Avatar answered Jan 22 '23 04:01

BobTheBuilder


instanceof operator is used to determine that. It's infix, so use it like so...

(value instanceof MyClass)
like image 30
alex Avatar answered Jan 22 '23 06:01

alex