Post

KotlinKotlin

j
jordan chris

Posted on 27th February 2024|36 views

0
votes

Kotlin Instance Of

How can we check the class instance of in kotlin?

Answers
P
Harshel Mike

Posted on 27th February 2024

Class "instance of" can be checked by using the keyword is or !is

A simple example is given below: 

if(myInstance is string)

{

print(string)

}

if(myInstance !is string)

{

print(not a string)

}

else

{

print(null)

}

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos