我期望的是,当potentialByteArray instanceof byte[]potentialByteArray的实例时,byte[]将返回true,但这似乎没有发生-由于某种原因,它始终为false!

我有一个条件,如下所示:

if (!(potentialByteArray instanceof byte[])) { /* ... process ... */ }
else  {
        log.warn("--- can only encode 'byte[]' message data (got {})", msg.getClass().getSimpleName());
        /* ... handle error gracefully ... */
    }

...输出的内容如下:
--- can only encode 'byte[]' message data (got byte[])

这意味着该对象实际上是一个byte[],但不是某种程度上的instanceof byte[]。那么...这会适合Byte[]还是其他功能?这里到底发生了什么,为什么它不能按我期望的那样工作?

代替这里使用的合适成语是什么?

最佳答案

看来您有不需要的!(不是)

if (!(potentialByteArray instanceof byte[])) {...}

应该
if (potentialByteArray instanceof byte[]) {...}

10-04 23:25
查看更多