Top "Instanceof" questions

instanceof is an operator available in some object-oriented languages, including Java, php and JavaScript.

Objective c isKindOfClass missunderstanding?

I have following structure of objects: Animal, Dog and Cat. As You expect Dog and Cat are inherited from Animal. …

objective-c instanceof
How do you check both the exception's type as well as they type of the nested exception?

Suppose I catch an exception that is of type AppException but I only want to carry out certain actions on …

java exception instanceof
How to "instanceof" a primitive string (string literal) in JavaScript

In JavaScript, I can declare a string in the following ways; var a = "Hello World"; var b = new String("Hello …

javascript string instanceof string-literals
Is instanceof considered bad practice? If so, under what circumstances is instanceof still preferable?

Over the years, I've tried to avoid instanceof whenever possible. Using polymorphism or the visitor pattern where applicable. I suppose …

java instanceof
Passing a class as an argument to a method in java

I am writing a method were I would like to pass a class to a method, where a part of …

java argument-passing instanceof
Get type of a variable in Kotlin

How can I find the variable type in Kotlin? In Java there is instanceof, but Kotlin does not exist: val …

kotlin instanceof
Why can't a "Class" variable be passed to instanceof?

Why doesn't this code compile? public boolean isOf(Class clazz, Object obj){ if(obj instanceof clazz){ return true; }else{ return …

java class instanceof
See if two object have the same type

Let's say that I have a class A, and that B,C,D are derived from A. If I want …

java instanceof
Java - is there a "subclassof" like instanceof?

Im overriding an equals() method and I need to know if the object is an instance of a Event's subclass (…

java subclass equals instanceof
Why cast after an instanceOf?

In the example below (from my coursepack), we want to give to the Square instance c1 the reference of some …

java polymorphism instanceof