Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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. 
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

you can check on runtimeType for example

if (obj.runtimeType == parentClass){
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading