Scala

Scala

Made by DeepSource

Unary operator is redundant due to its operand SC-R1064

Anti-pattern
Major

A unary operator is an operator that takes a single operand. However, in this case, the operand supplied to the operator effectively negates or renders the operator redundant. To put it simply, the operand supplied undoes whatever the unary operator accomplishes.

Bad Practice

val b1 = true
val i  = 0

val b2 = !(!b1) // Effectively same as `b1`
val j  = ~(~i)  // Effectively same as `i`

Recommended

val b1 = true
val i  = 0

val b2 = b1 // Effectively same as `b1`
val j  = i  // Effectively same as `i`