2012-06-24 17 views
13

Ist es möglich, das Gegenteil von instanceof in Java zu bekommen? Ich habe Code wie folgt probiert:Das Gegenteil von instanceof

if(example !instanceof blarg).... 

aber es lässt mich nicht setzen! überall ohne einen Fehler, bitte helfen.

+1

bezogen werden: http://stackoverflow.com/questions/9068150/best- Weg zu negieren-ein-instanceof –

Antwort

47

Sie haben die ganze Sache zu negieren:

if(!(example instanceof blarg)) 
0

Als Alternative nutzen isInstance Methode:

if (!example.class.isInstance(blarg)) 
    { 
    // your code here 
    }