TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
* token in Kotlin functions as a binary arithmetic operator for multiplication, a unary prefix spread operator for array unpacking, a star projection token within the generic type system, and a wildcard character in import directives.
Binary Arithmetic Operator (Multiplication)
As a binary operator,* performs arithmetic multiplication. Kotlin resolves this via operator overloading, mapping the * symbol to the times() member or extension function.
* operator for custom classes, the type must declare a function named times accompanied by the operator modifier. The operand type and return type are strictly defined by the function signature.
Unary Prefix Spread Operator
When positioned as a prefix immediately preceding an array identifier,* acts as the spread operator. It unpacks the elements of an array, allowing them to be passed as discrete arguments to a function parameter declared with the vararg modifier.
- Type Restriction: The spread operator is strictly compatible with arrays (e.g.,
Array<T>,IntArray,DoubleArray). It cannot be applied directly to aCollection<T>(which requires conversion via.toTypedArray()) or a pureIterable<T>(which requires conversion via.toList().toTypedArray()). - Memory Allocation and Mutation: Invoking the spread operator creates a shallow copy of the array elements. For object types, a
varargparameter compiles toArray<out T>, where theoutvariance inherently prevents element mutation at compile time. However, for primitive arrays (e.g.,IntArray), element mutation is permitted. In these cases, the shallow copy ensures that any modifications to the array’s elements within the function do not affect the original array. - Argument Composition: The operator can be interleaved with standard, comma-separated arguments within the same function invocation.
Star Projection (Generics)
While structurally a type projection rather than an expression-level operator,* is utilized within angle brackets to denote an unknown type argument in parameterized types.
* provides a safe approximation of a generic type based on its variance declaration and upper bounds:
- For a covariant type parameter (
out T : TUpper),*projects toout TUpper, allowing safe reads of the upper bound. If no explicit upper bound is declared, it defaults toout Any?. - For a contravariant type parameter (
in T),*projects toin Nothing, preventing unsafe writes to the generic instance. - For an invariant type parameter (
T : TUpper),*projects toout TUpperfor reading andin Nothingfor writing.
Wildcard Import
In file headers, the* token acts as a wildcard within import directives. It instructs the compiler to import all accessible top-level declarations (classes, interfaces, functions, and properties) from a specified package or classifier, eliminating the need to import each member individually.
Master Kotlin with Deep Grasping Methodology!Learn More





