caarlos0 caarlos0 - 12 days ago 10
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?




EDIT:
By beautiful, I might say something like this:

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

Answer

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