• PyQt5 ebook
  • Tkinter ebook
  • SQLite Python
  • wxPython ebook
  • Windows API ebook
  • Java Swing ebook
  • Java games ebook
  • MySQL Java ebook

Kotlin operators

last modified January 29, 2024

In this article we cover Kotlin operators. We show how to use operators to create expressions.

An operator is a special symbol which indicates a certain process is carried out. Operators in programming languages are taken from mathematics. Programmers work with data. The operators are used to process data. An operand is one of the inputs (arguments) of an operator.

Expressions are constructed from operands and operators. The operators of an expression indicate which operations to apply to the operands. The order of evaluation of operators in an expression is determined by the precedence and associativity of the operators.

An operator usually has one or two operands. Those operators that work with only one operand are called unary operators . Those who work with two operands are called binary operators .

Certain operators may be used in different contexts. For instance the + operator can be used in different cases: it adds numbers, concatenates strings, or indicates the sign of a number. We say that the operator is overloaded .

Kotlin sign operators

There are two sign operators: + and - . They are used to indicate or change the sign of a value.

The + and - signs indicate the sign of a value. The plus sign can be used to signal that we have a positive number. It can be omitted and it is in most cases done so.

The minus sign changes the sign of a value.

Kotlin assignment operator

The assignment operator = assigns a value to a variable. A variable is a placeholder for a value. In mathematics, the = operator has a different meaning. In an equation, the = operator is an equality operator. The left side of the equation is equal to the right one.

Here we assign a number to the x variable.

This expression does not make sense in mathematics, but it is legal in programming. The expression adds 1 to the x variable. The right side is equal to 2 and 2 is assigned to x .

This code line results in syntax error. We cannot assign a value to a literal.

Kotlin augmented assignment operators

Augmented assignment operators are shorthand operators which consist of two operators. Augmented assignment operators are also called compound assignment operatos in other programming languages.

The += compound operator is one of these shorthand operators. The above two expressions are equal. Value 3 is added to the a variable.

The Kotlin augmented assignment operators are:

The following example uses two compound operators.

We use the += and *= compound operators.

The a variable is initiated to one. Value 1 is added to the variable using the non-shorthand notation.

Using a += compound operator, we add 5 to the a variable. The statement is equal to a = a + 5 .

Using the *= operator, the a is multiplied by 3. The statement is equal to a = a * 3 .

Kotlin concatenating strings

In Kotlin the + operator is also used to concatenate strings.

We join three strings together.

Strings are joined with the + operator.

An alternative method for concatenating strings is the plus method.

Kotlin increment and decrement operators

Incrementing or decrementing a value by one is a common task in programming. Kotlin has two convenient operators for this: ++ and -- .

The above two pairs of expressions do the same.

In the above example, we demonstrate the usage of both operators.

We initiate the x variable to 6. Then we increment x two times. Now the variable equals to 8.

We use the decrement operator. Now the variable equals to 7.

Kotlin arithmetic operators

The following is a table of arithmetic operators in Kotlin.

The following example shows arithmetic operations.

In the preceding example, we use addition, subtraction, multiplication, division, and remainder operations. This is all familiar from the mathematics.

The % operator is called the remainder or the modulo operator. It finds the remainder of division of one number by another. For example, 9 % 4 , 9 modulo 4 is 1, because 4 goes into 9 twice with a remainder of 1.

There is a distinction between integer and floating point division.

In the preceding example, we divide two numbers.

In this code, we have done integer division. The returned value of the division operation is an integer. When we divide two integers the result is an integer.

If one of the values is a double or a float, we perform a floating point division. In our case, the second operand is a double so the result is a double.

We see the result of the program.

Kotlin Boolean operators

In Kotlin we have three logical operators.

Boolean operators are also called logical.

Many expressions result in a boolean value. For instance, boolean values are used in conditional statements.

Relational operators always result in a boolean value. These two lines print false and true.

The body of the if statement is executed only if the condition inside the parentheses is met. The y > x returns true, so the message "y is greater than x" is printed to the terminal.

The true and false keywords represent boolean literals in Kotlin.

The code example shows the logical and (&&) operator. It evaluates to true only if both operands are true.

Only one expression results in true.

The logical or ( || ) operator evaluates to true if either of the operands is true.

If one of the sides of the operator is true, the outcome of the operation is true.

Three of four expressions result in true.

The negation operator ! makes true false and false true.

The example shows the negation operator in action.

Kotlin comparison operators

Comparison operators are used to compare values. These operators always result in a boolean value.

comparison operators are also called relational operators.

In the code example, we have four expressions. These expressions compare integer values. The result of each of the expressions is either true or false. In Kotlin we use the == to compare numbers. (Some languages like Ada, Visual Basic, or Pascal use = for comparing numbers.)

Kotlin bitwise operations

Unlike in Java, there are no bitwise operators in Kotlin. Kotlin has named functions that perform bitwise operations.

  • shl(bits) – signed shift left (Java's <<)
  • shr(bits) – signed shift right (Java's >>)
  • ushr(bits) – unsigned shift right (Java's >>>)
  • and(bits) – bitwise and
  • or(bits) – bitwise or
  • xor(bits) – bitwise xor
  • inv() – bitwise inversion

These functions are available for Int and Long types only.

The bitwise and operation performs bit-by-bit comparison between two numbers. The result for a bit position is 1 only if both corresponding bits in the operands are 1.

The first number is a binary notation of 6, the second is 3 and the result is 2.

The bitwise or operation performs bit-by-bit comparison between two numbers. The result for a bit position is 1 if either of the corresponding bits in the operands is 1.

The result is 00110 or decimal 7.

Kotlin is operator

To check whether an object conforms to a given type at runtime we can use the is operator or its negated form !is .

In the example, we have two classes: one base and one derived from the base.

This line checks if the variable d points to the class that is an instance of the Base class. Since the Derived class inherits from the Base class, it is also an instance of the Base class too. The line prints true.

The b object is not an instance of the Derived class. This line prints false.

Every class has Any as a superclass. Therefore, the d object is also an instance of the Any class.

Kotlin lambda operator

Kotlin has lambda operator ( -> ). It separates the parameters and body of a lambda expression.

In the example, we define an array of strings. The array is sorted using the Arrays.sort method and a lambda expression.

Kotlin double colon operator

The double colon operator (::) is used to create a class or a function reference.

In the code example, we create a reference to a class and to a function with the double colon operator.

With the double colon operator, we refer to the String class. We print all its ancestors.

Here we apply the length function on all words of a list.

Kotlin range operator

The Kotlin range operator (..) allows to create ranges of values.

The example uses the range operator to create a sequence of integers in a for loop.

Non-null assertion operator

The non-null assertion operator (!!) converts any value to a non-null type and throws an exception if the value is null.

The example counts the number of characters in the list of words. If the list contains a null value, a KotlinNullPointerException it thrown.

Kotlin Elvis operator

The Elvis operator ?: returns its first expression if it is not null, otherwise it returns the second expression.

In the example we check for null values in the list with the Elvis operator.

The ?: returns 0 if the variable word contains null.

Kotlin null-safety operator

Kotlin's null-safety operator ?. provides a safe method call—a method is called only if the object is not null.

In the example, we convert strings to uppercase; we use null-safety operator. For the null value, the method is not called.

Kotlin index access operator

Kotlin index access operator is used to get a obtain a value from an array.

In the example, we retrieve two values from an array with the [] operator.

Kotlin referential equality operator

Kotlin differentiates between structural and referential equality. Structural equality operator ( == ) checks if two objects have the same content. Referential equality operator ( === ) checks if variables point to the same object in memory.

The example demonstrates the difference between == and === operators.

Kotlin operator precedence

The operator precedence tells us which operators are evaluated first. The precedence level is necessary to avoid ambiguity in expressions.

What is the outcome of the following expression, 28 or 40?

Like in mathematics, the multiplication operator has a higher precedence than addition operator. So the outcome is 28.

To change the order of evaluation, we can use parentheses. Expressions inside parentheses are always evaluated first. The result of the above expression is 40.

In this code example, we show a few expressions. The outcome of each expression is dependent on the precedence level.

This line prints 28. The multiplication operator has a higher precedence than addition. First, the product of 5 * 5 is calculated, then 3 is added.

The evaluation of the expression can be altered by using round brackets. In this case, the 3 + 5 is evaluated and later the value is multiplied by 5. This line prints 40.

In this case, the negation operator has a higher precedence than the bitwise or. First, the initial true value is negated to false, then the | operator combines false and true, which gives true in the end.

Associativity rule

Sometimes the precedence is not satisfactory to determine the outcome of an expression. There is another rule called associativity . The associativity of operators determines the order of evaluation of operators with the same precedence level.

What is the outcome of this expression, 9 or 1? The multiplication, deletion, and the modulo operator are left to right associated. So the expression is evaluated this way: (9 / 3) * 3 and the result is 9.

Arithmetic, boolean and relational operators are left to right associated. The ternary operator, increment, decrement, unary plus and minus, negation, bitwise not, type cast, object creation operators are right to left associated.

In the example, we the associativity rule determines the outcome of the expression.

The enhanced assignment operators are right to left associated. We might expect the result to be 1. But the actual result is 0. Because of the associativity. The expression on the right is evaluated first and then the compound assignment operator is applied.

Calculating prime numbers

In the following example, we are going to calculate prime numbers.

In the above example, we deal with several operators. A prime number (or a prime) is a natural number that has exactly two distinct natural number divisors: 1 and itself. We pick up a number and divide it by numbers from 1 to the selected number. Actually, we do not have to try all smaller numbers; we can divide by numbers up to the square root of the chosen number. The formula will work. We use the remainder division operator.

We will calculate primes from these numbers.

Values 0 and 1 are not considered to be primes.

We skip the calculations for 2 and 3. They are primes. Note the usage of the equality and conditional or operators. The == has a higher precedence than the || operator. So we do not need to use parentheses.

We are OK if we only try numbers smaller than the square root of a number in question.

This is a while loop. The i is the calculated square root of the number. We use the decrement operator to decrease i by one each loop cycle. When i is smaller than 1, we terminate the loop. For example, we have number 9. The square root of 9 is 3. We will divide the 9 number by 3 and 2. This is sufficient for our calculation.

If the remainder division operator returns 0 for any of the i values, then the number in question is not a prime.

Kotlin keywords and operators - language reference

In this article we covered Kotlin operators.

My name is Jan Bodnar and I am a passionate programmer with many years of programming experience. I have been writing programming articles since 2007. So far, I have written over 1400 articles and 8 e-books. I have over eight years of experience in teaching programming.

List all Kotlin tutorials .

kotlin assignment operators ambiguity

Learn Python practically and Get Certified .

Popular Tutorials

Popular examples, reference materials, learn python interactively, kotlin introduction.

  • Kotlin Hello World - Your First Kotlin Program
  • Kotlin Comments

Kotlin Fundamentals

  • Kotlin Variables and Basic Types

Kotlin Type Conversion

  • Kotlin Operators: Arithmetic, Assignment Operator and More
  • Kotlin Expression, Statements and Blocks
  • Kotlin Basic Input/Output

Kotlin Flow Control

  • Kotlin if...else Expression
  • Kotlin when Expression
  • Kotlin while and do...while Loop
  • Kotlin for Loop
  • Kotlin break
  • Kotlin continue

Kotlin Functions

  • Kotlin Function (With Example)
  • Kotlin Function Call Using Infix Notation
  • Kotlin Default and Named Arguments
  • Kotlin Recursion and Tail Recursive Function
  • Kotlin Class and Objects
  • Kotlin Constructors and Initializers
  • Kotlin Getters and Setters (With Example)
  • Kotlin Inheritance
  • Kotlin Visibility Modifiers
  • Kotlin Abstract Class and Abstract Members
  • Kotlin Interfaces
  • Kotlin Nested and Inner Class
  • Kotlin Data Class
  • Kotlin Sealed Classes
  • Kotlin Object Declarations and Expressions
  • Kotlin Companion Objects
  • Kotlin Extension Function

Kotlin Operator Overloading

Additional Topics

  • Kotlin Keywords and Identifiers
  • Kotlin String and String Templates
  • Kotlin Lambdas

Kotlin Bitwise and Bitshift Operations

Kotlin Tutorials

Kotlin if Expression

Kotlin Operators

Operators are special symbols (characters) that carry out operations on operands (variables and values). For example, + is an operator that performs addition.

In Java variables article, you learned to declare variables and assign values to variables. Now, you will learn to use operators perform various operations on them.

1. Arithmetic Operators

Here's a list of arithmetic operators in Kotlin:

Example: Arithmetic Operators

When you run the program, the output will be:

The + operator is also used for the concatenation of String values.

Example: Concatenation of Strings

How arithmetic operators actually work.

Suppose, you are using + arithmetic operator to add two numbers a and b .

Under the hood, the expression a + b calls a.plus(b) member function. The plus operator is overloaded to work with String values and other basic data types (except Char and Boolean ).

You can also use + operator to work with user-defined types (like objects) by overloading plus() function.

Recommended Reading: Kotlin Operator Overloading

Here's a table of arithmetic operators and their corresponding functions:

2. Assignment Operators

Assignment operators are used to assign value to a variable. We have already used simple assignment operator = before.

Here, 5 is assigned to variable age using = operator.

Here's a list of all assignment operators and their corresponding functions:

Example: Assignment Operators

Recommended Reading: Overloading assignment operators in Kotlin .

3. Unary prefix and Increment / Decrement Operators

Here's a table of unary operators, their meaning, and corresponding functions:

Example: Unary Operators

Recommended Reading: Overloading Unary Operators

4. Comparison and Equality Operators

Here's a table of equality and comparison operators, their meaning, and corresponding functions:

Comparison and equality operators are used in control flow such as if expression , when expression , and loops .

Example: Comparison and Equality Operators

Recommended Reading: Overloading of Comparison and Equality Operators in Kotlin

5. Logical Operators

There are two logical operators in Kotlin: || and &&

Here's a table of logical operators, their meaning, and corresponding functions.

Note that, or and and are functions that support infix notation .

Logical operators are used in control flow such as if expression , when expression , and loops .

Example: Logical Operators

Recommended Reading: Overloading of Logical Operators in Kotlin

6. in Operator

The in operator is used to check whether an object belongs to a collection.

Example: in Operator

Recommended Reading: Kotlin in Operator Overloading

7. Index access Operator

Here are some expressions using index access operator with corresponding functions in Kotlin.

Example: Index access Operator

Recommended Reading: Kotlin Index access operator Overloading

8. Invoke Operator

Here are some expressions using invoke operator with corresponding functions in Kotlin.

In Kotlin, parenthesis are translated to call invoke member function.

Recommended Reading: Invoke Operator Overloading in Kotlin

Bitwise Operation

Unlike Java, there are no bitwise and bitshift operators in Kotlin. To perform these task, various functions (supporting infix notation) are used:

  • shl - Signed shift left
  • shr - Signed shift right
  • ushr - Unsigned shift right
  • and - Bitwise and
  • or - Bitwise or
  • xor - Bitwise xor
  • inv - Bitwise inversion

Visit this page to learn more about Bitwise Operations in Kotlin .

Also, there is no ternary operator in Kotlin unlike Java.

Table of Contents

  • What is an operator?
  • How (arithmetic) operators work under the hood?
  • Index Access Operators
  • Invoke Operator

Sorry about that.

Related Tutorials

Kotlin Tutorial

Strange behaviour with collection plusAssign operator

I ran into a strange operator ambiguity when using += on a mutable variable of collection (Set, List).

image

When the variable is not var , it works correctly, because the compiler doesn’t want to release the assignment c += 1 to an = and a + .

There are workarounds (using val or use the named call of the operator ( assignPlus ), but I think in this case the intention is clear and can’t recall a use case when one means the other way. So the clear precedency goes for the plusAssign .

Is it? Do you want to call

IMO both are equally implied by the += syntax but 1 modifies the original list while the other creates a copy. This can easily lead to confusion and create bugs. There aleady was a discussion about this exact syntax here but I can’t find it right now, but from what I remember the consens was that += isn’t really a good idea to use for lists or mutable lists. The first can easily lead to loads of unintentional copy operations turning a simple loop int o a O(n^2) operation while the other leads to ambiguity.

Related Topics

Kotlin Android

Kotlin basics.

  • Kotlin Hello World
  • Kotlin Ranges
  • Kotlin Arrays
  • Kotlin Programs
  • LinearLayout

Android Compose

  • Kotlin Tutorials
  • Kotlin Android Tutorials
  • Android Compose Tutorials
  • Kotlin Android Home
  • → Kotlin Tutorials
  • →→ Kotlin Operators
  • Introduction to Kotlin language
  • Kotlin Variables
  • Kotlin Comments
  • Kotlin if-else
  • Kotlin While loop
  • Kotlin Do..While loop
  • Kotlin For loop
  • Kotlin break
  • Kotlin continue
  • Kotlin Arrays Tutorials
  • Kotlin String Tutorials

Kotlin Operators

Operators in kotlin.

Kotlin Operators are Arithmetic Operators, Assignment Operators, Comparison Operators, and Logical Operators.

In Kotlin language, operators are used to perform operations on given values. The operations could be mathematical, logical, etc. Based on the operation and requirement, the input values can be numeric, boolean, strings, etc.

For example, Arithmetic Addition operator takes two numeric values as operands, finds the sum of the two given numbers, and returns the result.

In this tutorial, we will go through all of the operators available in Kotlin, with examples, and references to the individual tutorials for each of the operators.

Arithmetic Operators

The following table covers Arithmetic Operators in Kotlin.

In the following program, we take two numbers: x , and y ; and perform Arithmetic Operations on these numbers.

Kotlin Program

The following tutorials cover Arithmetic Operators in detail with syntax and examples.

  • Kotlin Addition
  • Kotlin Subtraction
  • Kotlin Multiplication
  • Kotlin Division
  • Kotlin Modulus
  • Kotlin Increment
  • Kotlin Decrement

Assignment Operators

The following table covers Assignment Operators in Kotlin.

In the following program, we take a variable x , and apply different assignment operators on it with a value of 5 .

The following tutorials cover Assignment Operators in detail.

  • Kotlin Assignment
  • Kotlin Addition Assignment
  • Kotlin Subtraction Assignment
  • Kotlin Multiplication Assignment
  • Kotlin Division Assignment
  • Kotlin Modulus Assignment

Comparison Operators

The following table covers Comparison Operators in Kotlin.

In the following program, we take two numbers: a , and b ; and perform comparison operations on these numbers.

The following tutorials cover Comparison Operators in detail.

  • Kotlin Equal-to
  • Kotlin Not-equal
  • Kotlin Greater-than
  • Kotlin Less-than
  • Kotlin Greater-than or Equal-to
  • Kotlin Less-than or Equal-to

Logical Operators

The following table covers Logical Operators in Kotlin.

In the following program, we take boolean values in a , and b ; and perform logical operations on these values.

The following tutorials cover Logical Operators in detail with syntax and examples.

More Tutorials on Operators

These are some more tutorials related to Kotlin Operators.

  • Kotlin If AND
  • Kotlin If OR

IMAGES

  1. The Best Way to Understand Kotlin Operators

    kotlin assignment operators ambiguity

  2. arraylist

    kotlin assignment operators ambiguity

  3. The Best Way to Understand Kotlin Operators

    kotlin assignment operators ambiguity

  4. All Kotlin Operators Explained!

    kotlin assignment operators ambiguity

  5. The Best Way to Understand Kotlin Operators

    kotlin assignment operators ambiguity

  6. The Best Way to Understand Kotlin Operators

    kotlin assignment operators ambiguity

VIDEO

  1. Impurities in CFG and Transformation

  2. Kotlin Operators

  3. Mastering Kotlin

  4. Kotlin

  5. Kotlin

  6. 2. Kotlin Basics in Bangla-Arithmatic Operators

COMMENTS

  1. Handling Assignment operators ambiguity in Android Studio(Kotlin)

    Handling Assignment operators ambiguity in Android Studio(Kotlin) Ask Question Asked 5 years, 11 months ago. Modified 5 years, 7 months ago. Viewed 1k times ... I think there is no need to stick to the assignment operator after all, it's just a convenient way to the method calls :) Share.

  2. Operator overloading

    Kotlin allows you to provide custom implementations for the predefined set of operators on types. These operators have predefined symbolic representation (like + or *) and precedence.To implement an operator, provide a member function or an extension function with a specific name for the corresponding type. This type becomes the left-hand side type for binary operations and the argument type ...

  3. kotlin

    The strange += operator in Kotlin. you can both overloading the plus operator and plusAssign operator in kotlin, but you must following the rules of kotlin to solving the strange += conflicts.. introduce an immutable structure of the class for the plus operator which means any class outside the class can't edit its internal data.. introduce a mutable structure of the class for the plusAssign ...

  4. Kotlin language specification

    An operator assignment is a combined-form assignment which involves one of the following operators: +=, -=, *=, ... this should be reported as an operator overloading ambiguity. ... The only form of a for-loop available in Kotlin is the "foreach" loop, which iterates over lists, arrays and other data structures. ...

  5. Compiler Error: Assignment operators ambiguity. All these functions

    © 2000-2024 JetBrains. All rights reserved Sponsored and developed by

  6. Operator Overloading in Kotlin: A Primer

    In Kotlin, operators are overloaded by implementing functions in your class. These functions must be marked with the operator modifier. Here is an example: data class Fraction(val numerator: Int ...

  7. Operators in Kotlin

    Kotlin assignment operator. The assignment operator = assigns a value to a variable. ... The precedence level is necessary to avoid ambiguity in expressions. What is the outcome of the following expression, 28 or 40? ... The enhanced assignment operators are right to left associated. We might expect the result to be 1. But the actual result is 0.

  8. Kotlin Assignment Operator

    Kotlin Assignment Operator assigns the right operand, usually a value or an expression, to the left operand, usually a variable or constant. In this tutorial, you will learn how to use Assignment operator, with syntax and examples.

  9. Mastering Kotlin Operators: A Comprehensive Guide.

    The most common assignment operator is the simple assignment operator (=), but Kotlin also offers compound assignment operators that combine an operation with assignment, such as +=, -=, *=, and /=.

  10. Plus and minus operators

    For the details on plus and minus operators for maps, see Map specific operations.The augmented assignment operators plusAssign (+=) and minusAssign (-=) are also defined for collections.However, for read-only collections, they actually use the plus or minus operators and try to assign the result to the same variable. Thus, they are available only on var read-only collections.

  11. Cannot add an element to a collection with

    Error: Kotlin: Assignment operators ambiguity: public operator fun Set.plus(element: String): Set defined in kotlin.collections @InlineOnly public inline operator fun MutableCollection.plusAssign(element: String): Unit defined in kotlin.collections. This seems silly; how can + and += ever be ambiguous? I clearly typed +=! Also, while using + is ...

  12. Why Kotlin doesn't allow assignments as expressions?

    Thus, assignment cannot occur within expressions without introducing substantial ambiguity. (Other languages can avoid this by using a different syntax for named arguments, by having a separate inline assignment operator, or by requiring inline assignments to be parenthesized, e.g. var x = 0; foo(bar = (x = 42)).)

  13. Kotlin Operators: Arithmetic, Assignment Operator and More

    2. Assignment Operators. Assignment operators are used to assign value to a variable. We have already used simple assignment operator = before. val age = 5. Here, 5 is assigned to variable age using = operator. Here's a list of all assignment operators and their corresponding functions: Expression. Equivalent to.

  14. Strange behaviour with collection plusAssign operator

    Language Design. I ran into a strange operator ambiguity when using += on a mutable variable of collection (Set, List). When the variable is not var, it works correctly, because the compiler doesn't want to release the assignment c += 1 to an = and a +. There are workarounds (using val or use the named call of the operator ( assignPlus ), but ...

  15. Kotlin Assignment Operators

    Kotlin Assignment Operators. Kotlin Assignment Operators are used to assign a value or a computed value to a variable. In this tutorial, we shall learn about Assignment Operators, their symbols, and how to use them in a Kotlin program. Table for Assignment Operators. The following table covers Assignment Operators in Kotlin.

  16. Conventions in Kotlin

    The += operator can be transformed into either the plus or the plusAssign function call. However, there can be ambiguity when both the regular operator function and the compound assignment operator function are applicable.. To illustrate, let's consider the example of the plusAssign function defined for a mutable collection in the Kotlin standard library:

  17. hard-to-understand error in an augmented assignment statement in Kotlin

    It is just a call to the plusAssign operator function. There are many overloads of plusAssign. The relevant ones to this question are: operator fun <T> MutableCollection<in T>.plusAssign( element: T) operator fun <T> MutableCollection<in T>.plusAssign( elements: Iterable<T>)

  18. is there a way to resolve an ambiguous += to a list `cliOpti kotlinlang

    clioptions is a java List. Copy code. Assignment operators ambiguity. All these functions match. public operator fun <T> Collection<CliOption!>.plus(element: CliOption!): List<CliOption!> defined in kotlin.collections. public inline operator fun <T> MutableCollection<in CliOption>.plusAssign(element: CliOption): Unit defined in kotlin.collections.

  19. Kotlin Operators

    In Kotlin language, operators are used to perform operations on given values. The operations could be mathematical, logical, etc. Based on the operation and requirement, the input values can be numeric, boolean, strings, etc. For example, Arithmetic Addition operator takes two numeric values as operands, finds the sum of the two given numbers ...

  20. In Kotlin, what is the difference between assignment and assignment

    Assignment: It's an operation that gives a value to a variable. In Kotlin, assignment uses the = operator. For instance: val x = 10 or var y: Int; y = 20. Assignments in Kotlin do not evaluate to a value. Therefore, you can't do things like val z = (y = x), because (y = x) doesn't produce a value. Assignment Expressions:

  21. Kotlin's List missing "add", "remove", Map missing "put", etc?

    Unlike many languages, Kotlin distinguishes between mutable and immutable collections (lists, sets, maps, etc). Precise control over exactly when collections can be edited is useful for eliminating bugs, and for designing good APIs. ... Error: Kotlin: Assignment operators ambiguity: public operator fun Collection.plus(element: ...