About 1,370,000 results
Open links in new tab
  1. operators - Use of "instanceof" in Java - Stack Overflow

    Jul 22, 2019 · What is the 'instanceof' operator used for? I learned that Java has the instanceof operator. Can you elaborate where it is used and what are its advantages?

  2. What is the 'instanceof' operator used for in Java?

    The java instanceof operator is used to test whether the object is an instance of the specified type (class or subclass or interface). The instanceof in java is also known as type comparison operator as it …

  3. java - Is null check needed before calling instanceof? - Stack Overflow

    Jun 1, 2010 · No, a null check is not needed before using instanceof. The expression x instanceof SomeClass is false if x is null. The Java 11 Language Specification expresses this concisely in …

  4. java - How to determine an object's class? - Stack Overflow

    If class B and class C extend class A and I have an object of type B or C, how can I determine of which type it is an instance?

  5. Java: Instanceof and Generics - Stack Overflow

    Oct 15, 2009 · Cannot perform instanceof check against type parameter E. Use instead its erasure Object since generic type information will be erased at runtime What is the better way to do it?

  6. java - How instanceof will work on an interface - Stack Overflow

    Nov 21, 2012 · 70 instanceof can be used to test if an object is a direct or descended instance of a given class. instanceof can also be used with interfaces even though interfaces can't be instantiated like …

  7. java - Assert an object is a specific type - Stack Overflow

    Sep 13, 2012 · Is it possible in JUnit to assert an object is an instance of a class? For various reasons I have an object in my test that I want to check the type of. Is it a type of Object1 or a type of Object2?

  8. java - Best way to "negate" an instanceof - Stack Overflow

    This has different behaviour. The instanceof keyword includes subclasses, the method does not, you need to use Class.isAssignableFrom to replicate the behaviour.

  9. java - instanceof Vs getClass ( ) - Stack Overflow

    Don't use isAssignableFrom. The correct way to write o instanceof String using reflection is String.getClass().isInstance(o). The javadoc even says so: This method is the dynamic equivalent of …

  10. java - how to instanceof List<MyType>? - Stack Overflow

    Apr 11, 2012 · For example - I have a local variable value which returns Object, and I need to check - if it's a list, if it is, check if the list type instanceof my interface.