In kotlin class, I have method parameter as object (See kotlin doc here ) for class type T. As object I am passing different classes when I am calling method.
In Java we can able to compare class using instanceof
of object which class it is.
So I want to check and compare at runtime which Class it is?
How can I check instanceof class in kotlin?
Use
is
.or the reverse
!is
Try using keyword called
is
Official page referenceWe can check whether an object conforms to a given type at runtime by using the
is
operator or its negated form!is
.Example:
Another Example in case of Custom Object:
Let, I have an
obj
of typeCustomObject
.Combining
when
andis
:copied from official documentation
You can use
is
: