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.
Short is a 16-bit signed two’s complement integer data type in Kotlin. It occupies 2 bytes of memory and represents numerical values strictly within the range of -32,768 to 32,767 ( to ).
Memory and Bounds Constants
TheShort companion object provides constant properties to access its structural limits:
Short.MIN_VALUE: -32768Short.MAX_VALUE: 32767Short.SIZE_BYTES: 2Short.SIZE_BITS: 16
Instantiation and Syntax
Kotlin does not provide a dedicated literal suffix forShort (unlike L for Long or f for Float). Because integer literals are inferred as Int by default, a Short must be instantiated via explicit type declaration or explicit conversion.
JVM Representation and Boxing
On the Kotlin/JVM platform, the compiler mapsShort types based on nullability:
- Non-nullable (
Short): Compiles directly to the Java primitiveshort. - Nullable (
Short?): Triggers boxing, compiling to the Java wrapper classjava.lang.Short.
Type Promotion in Arithmetic
Kotlin enforces strict type safety and does not implicitly widen types. When performing arithmetic operations involvingShort, the compiler automatically promotes the operands to Int (or Long if the other operand is a Long) to prevent overflow during intermediate calculations.
Consequently, the return type of an arithmetic operation between two Short variables is an Int.
Bitwise Operations
As of Kotlin 1.5, the standard library provides strict bitwise operations directly for theShort type. The infix functions and, or, and xor, as well as the unary function inv(), can be invoked directly on a Short and will return a Short.
However, bitwise shift operations (shl, shr, ushr) are not defined on the Short class. To perform bit shifts, the Short must first be explicitly promoted to an Int.
Master Kotlin with Deep Grasping Methodology!Learn More





