is!
operator is used to check if an object is not of a specified type. While x is! Y
is an equivalent of !(x is
Y)
, it is preferred to use the first one. The x is! Y
syntax is more compact and more readable than the !(x is Y)
syntax. It is also less error-prone when used in complex expressions.
Noncompliant code example
if (!(x is Y)) {
print("$x is not Y!")
}
Compliant solution
if (x is! Y) {
print("$x is not Y!")
}