Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The opposite of instanceof [duplicate]

Is it possible to get the opposite of instanceof in java? I have tried code like this:

if( example !instanceof blarg)....

but it won't let me put the ! anywhere without an error, please help.

like image 967
Lolmister Avatar asked Jun 24 '12 22:06

Lolmister


People also ask

How do I know if not Instanceof?

To check if an object is not an instance of a class, use the logical NOT (!) operator to negate the use of the instanceof operator - !( obj instanceof Class) .

What does Instanceof mean?

instanceof is a binary operator we use to test if an object is of a given type. The result of the operation is either true or false. It's also known as a type comparison operator because it compares the instance with the type. Before casting an unknown object, the instanceof check should always be used.

What is pattern variable in java?

A pattern is a combination of (1) a predicate, or test, that can be applied to a target, and (2) a set of local variables, known as pattern variables, that are extracted from the target only if the predicate successfully applies to it.


1 Answers

You have to negate the entire thing:

if(!(example instanceof blarg))

You could also write it like so:

if(example instanceof blarg == false)
like image 97
Corbin Avatar answered Sep 28 '22 21:09

Corbin