Skip to content

Latest commit

 

History

History
36 lines (27 loc) · 952 Bytes

booleans.md

File metadata and controls

36 lines (27 loc) · 952 Bytes

The type Boolean represents boolean objects that can have two values: true and false.

On the JVM, booleans stored as primitive type: boolean, typically use 8 bits.

{type="note"}

Boolean has a nullable counterpart Boolean? that also has the null value.

Built-in operations on booleans include:

  • || – disjunction (logical OR)
  • && – conjunction (logical AND)
  • ! – negation (logical NOT)

|| and && work lazily.

fun main() {
//sampleStart
    val myTrue: Boolean = true
    val myFalse: Boolean = false
    val boolNull: Boolean? = null
    
    println(myTrue || myFalse)
    println(myTrue && myFalse)
    println(!myTrue)
//sampleEnd
}

{kotlin-runnable="true" kotlin-min-compiler-version="1.3"}

On the JVM, nullable references to boolean objects are boxed in Java classes, just like with numbers.

{type="note"}