Best way to “negate” an instanceof

后端 未结 9 1508
后悔当初
后悔当初 2021-01-30 02:01

I was thinking if there exists a better/nicer way to negate an instanceof in Java. Actually, I\'m doing something like:

if(!(str instanceof String))         


        
9条回答
  •  感动是毒
    2021-01-30 02:25

    I don't know what you imagine when you say "beautiful", but what about this? I personally think it's worse than the classic form you posted, but somebody might like it...

    if (str instanceof String == false) { /* ... */ }
    

提交回复
热议问题