I was thinking if there exists a better/nicer way to negate an instanceof in Java. Actually, I\'m doing something like:
instanceof
if(!(str instanceof String))
If you find it more understandable, you can do something like this with Java 8 :
public static final Predicate isInstanceOfTheClass = objectToTest -> objectToTest instanceof TheClass; public static final Predicate isNotInstanceOfTheClass = isInstanceOfTheClass.negate(); // or objectToTest -> !(objectToTest instanceof TheClass) if (isNotInstanceOfTheClass.test(myObject)) { // do something }