“否定”的最佳方式一个实例 [英] Best way to "negate" an instanceof
本文介绍了“否定”的最佳方式一个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在想是否存在更好/更好的方法来否定Java中的 instanceof
。
实际上,我正在做类似的事情:
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)) { /* do Something */ }
但我认为应该存在一个漂亮的语法。
But I think that a "beautiful" syntax to do this should exist.
有谁知道它是否存在,以及语法是什么样的?
Does anyone know if it exists, and how the syntax look like?
编辑:
美丽的,我可能会这样说:
By beautiful, I might say something like this:
if(str !instanceof String) { /* do Something */ } // compilation fails
推荐答案
不,没有更好的方法;你的是规范的。
No, there is no better way; yours is canonical.
这篇关于“否定”的最佳方式一个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文