Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
Long is a built-in numeric data type in Kotlin representing a 64-bit signed two’s complement integer. It accommodates values ranging from -9,223,372,036,854,775,808 (-263) to 9,223,372,036,854,775,807 (263 - 1).
Instantiation and Syntax
When assigning an integer literal to a variable explicitly typed asLong, the compiler automatically instantiates the literal as a Long. If the variable’s type is not explicitly declared, appending an uppercase L suffix forces the compiler to infer the type as Long. Additionally, any integer literal exceeding the maximum value of a 32-bit Int is automatically inferred as a Long. Kotlin strictly rejects the lowercase l suffix to prevent visual confusion with the digit 1.
Memory Representation and Boxing
When targeting the JVM, Kotlin optimizes memory by compiling a non-nullableLong directly to the Java primitive long.
However, if the variable is declared as nullable (Long?) or used in a generic context (e.g., List<Long>), the compiler boxes the value into a java.lang.Long object. This boxing process allocates memory on the heap and introduces object overhead.
Type Conversion
While Kotlin automatically adapts integer literals to an explicitly declaredLong type, it enforces strict type safety for variables and does not support implicit widening conversions. You cannot directly assign an existing Int, Short, or Byte variable to a Long variable. Explicit conversion using the toLong() function is mandatory.
Long to a smaller numeric type (like Int) requires toInt(). If the Long value exceeds the target type’s maximum capacity, the resulting value is truncated to the least significant bits.
Bitwise Operations
Kotlin does not use standard C-style bitwise operators (e.g.,<<, |, &). Instead, Long supports bitwise manipulation through named infix functions and standard functions. These operate directly on the 64-bit binary representation.
Master Kotlin with Deep Grasping Methodology!Learn More





