2011-08-30 6 views
3

내가 무엇을 기대할 것인가 'potentialByteArray instanceof byte[]potentialByteArraybyte[]의 인스턴스 일 때 true를 반환하지만 이것이 발생하지 않는 것처럼 보입니다. - 어떤 이유로 든 항상 거짓입니다!자바 instanceof 및 바이트 []

나는 다음과 같아야 조건부있어 :

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[]) 

a byte[] 그러나 여하튼 instanceof byte[]가 아니었다. 그래서 ... 대신이 일이 Byte[]일까요? 실제로 여기서 무슨 일이 벌어지고 있으며, 내가 기대하는대로 작동하지 않는 이유는 무엇입니까?

여기서 대신 사용하는 적절한 관용구는 무엇입니까? 그것은 당신처럼 보인다

답변

13

은 가지고 ! (안)은

if (potentialByteArray instanceof byte[]) {...} 
+1

신음해야

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

을 필요가 없습니다. 고맙습니다 :) –

관련 문제