The .not() operator function in Kotlin is a unary operator used for logical negation.
Blog
The .not() operator function in Kotlin is a unary operator used for logical negation. It essentially inverts the boolean value of an expression. Here’s a breakdown of its functionality:
Functionality:
Example code:
val isLoggedIn = falseval isNotLoggedIn = isLoggedIn.not() // isNotLoggedIn will be trueval hasPermission = trueval doesNotHavePermission = !hasPermission // This is equivalent to hasPermission.not()
Key Points:
In summary:
The .not()
operator function provides an alternative way to perform logical negation in Kotlin. While it works the same way as the !
operator, the !
operator is generally preferred for readability and simplicity.
Copyright ©2024 Preplaced.in
Preplaced Education Private Limited
Ibblur Village, Bangalore - 560103
GSTIN- 29AAKCP9555E1ZV