Home > Enterprise >  Is there a way to prevent a child class from passing as a parent class in (obj is parentClass)?
Is there a way to prevent a child class from passing as a parent class in (obj is parentClass)?

Time:12-06

Currently I have an if statement that checks if an object is a class, however the issue is that it is also passing if that object is a child a child of the class. I'm aware that this is useful in many cases but is there any way to make it so that only the parent class passes the if statement?

if (obj is parentClass){
// I want this to work only for parentClass not child classes. 
}

CodePudding user response:

you can check on runtimeType for example

if (obj.runtimeType == parentClass){
  • Related