caarlos0 caarlos0 - 1 month ago 18
Java Question

Best way to "negate" an instanceof

I was thinking if exist a better/nicer way to negate a instanceof in Java.
Actually, I do something like:

if(!(str instanceof String)) { /* do Something */ }

But, I think that should exist a "beautiful" syntax to do this.

Someone know if it exists and how the syntax look like?

By beautiful, I might say something like this:

if(str !instanceof String) { /* do Something */ } // compile failure


No, there is no better way; yours is canonical.