Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .teamcity/references/BuildApiPages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ fun scriptBuildHtml(version: String? = null, init: GradleBuildStep.() -> Unit =
tasks = "dokkaHtmlMultiModule"
gradleParams = "${if (version != null) "-PdeployVersion=\"$version\" " else ""}--no-daemon --no-configuration-cache"
useGradleWrapper = true
jdkHome = "%env.JDK_17_0%"
}.apply(init)

fun copyDokkaApiResult(
Expand Down
556 changes: 289 additions & 267 deletions docs/kr.tree

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions docs/labels.list
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@
<primary-label id="beta" name="Beta" short-name="β" href="components-stability.html#stability-levels-explained" color="tangerine">The feature is in Beta. It is almost stable, but migration steps may be required in the future. We'll do our best to minimize any changes you have to make.</primary-label>
<primary-label id="advanced" name="Advanced" short-name="☆" color="purple"></primary-label>
<primary-label id="eap" name="EAP" short-name="EAP" color="red">This functionality is available only in the latest EAP version.</primary-label>

<secondary-label id="eap" name="EAP" color="red">This functionality is available only in the latest EAP version.</secondary-label>
</labels>
2 changes: 1 addition & 1 deletion docs/topics/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,5 +380,5 @@ fun main() {
## What's next?

* To learn more about why we recommend using collections for most use cases, read our [Collections overview](collections-overview.md).
* Learn about other [basic types](basic-types.md).
* Learn about other [basic types](types-overview.md).
* If you are a Java developer, read our Java to Kotlin migration guide for [Collections](java-to-kotlin-collections-guide.md).
2 changes: 1 addition & 1 deletion docs/topics/basic-syntax.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[//]: # (title: Basic syntax)
[//]: # (title: Basic syntax overview)

This is a collection of basic syntax elements with examples. At the end of every section, you'll find a link to
a detailed description of the related topic.
Expand Down
5 changes: 5 additions & 0 deletions docs/topics/classes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
[//]: # (title: Classes)

> Before creating classes, consider using a [data class](data-classes.md) if the purpose is to store data.
> Alternatively, think about extending an existing class with an [extension](extensions.md), rather than creating a new one from scratch.
>
{style="tip"}

Like other object-oriented languages, Kotlin uses _classes_ to encapsulate data (properties) and behavior (functions)
for reusable, structured code.

Expand Down
4 changes: 4 additions & 0 deletions docs/topics/coding-conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ the given code style.
2. Switch on **Incorrect formatting** inspection.
Additional inspections that verify other issues described in the style guide (such as naming conventions) are enabled by default.

<!-- Replace with an external link when the guide is moved -->

For more information, see the [Migrate to Kotlin code style with IntelliJ IDEA](code-style-migration-guide.md) guide.

## Source code organization

### Directory structure
Expand Down
4 changes: 4 additions & 0 deletions docs/topics/command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,7 @@ kotlinc -script-templates org.example.CustomScriptDefinition -script custom.scri
```

For additional details, see the [KEEP-75](https://github.com/Kotlin/KEEP/blob/master/proposals/scripting-support.md).

## What's next?

[Create a console application based on Kotlin/JVM](jvm-get-started.md).
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[//]: # (title: Compatibility guide for Kotlin 1.3)
[//]: # (title: Compatibility guide for Kotlin 1.3.x)

_[Keeping the Language Modern](kotlin-evolution-principles.md)_ and _[Comfortable Updates](kotlin-evolution-principles.md)_ are among the fundamental
principles in Kotlin Language Design. The former says that constructs which obstruct language evolution should be removed,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[//]: # (title: Compatibility guide for Kotlin 1.4)
[//]: # (title: Compatibility guide for Kotlin 1.4.x)

_[Keeping the Language Modern](kotlin-evolution-principles.md)_ and _[Comfortable Updates](kotlin-evolution-principles.md)_ are among the fundamental
principles in Kotlin Language Design. The former says that constructs which obstruct language evolution should be removed,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[//]: # (title: Compatibility guide for Kotlin 1.5)
[//]: # (title: Compatibility guide for Kotlin 1.5.x)

_[Keeping the Language Modern](kotlin-evolution-principles.md)_ and _[Comfortable Updates](kotlin-evolution-principles.md)_ are among the fundamental
principles in Kotlin Language Design. The former says that constructs which obstruct language evolution should be removed,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[//]: # (title: Compatibility guide for Kotlin 1.6)
[//]: # (title: Compatibility guide for Kotlin 1.6.x)

_[Keeping the Language Modern](kotlin-evolution-principles.md)_ and _[Comfortable Updates](kotlin-evolution-principles.md)_ are among the fundamental principles in
Kotlin Language Design. The former says that constructs which obstruct language evolution should be removed, and the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[//]: # (title: Compatibility guide for Kotlin 1.7)
[//]: # (title: Compatibility guide for Kotlin 1.7.0)

_[Keeping the Language Modern](kotlin-evolution-principles.md)_ and _[Comfortable Updates](kotlin-evolution-principles.md)_ are among the fundamental principles in
Kotlin Language Design. The former says that constructs which obstruct language evolution should be removed, and the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[//]: # (title: Compatibility guide for Kotlin 1.8)
[//]: # (title: Compatibility guide for Kotlin 1.8.x)

_[Keeping the Language Modern](kotlin-evolution-principles.md)_ and _[Comfortable Updates](kotlin-evolution-principles.md)_ are among the fundamental principles in
Kotlin Language Design. The former says that constructs which obstruct language evolution should be removed, and the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[//]: # (title: Compatibility guide for Kotlin 1.9)
[//]: # (title: Compatibility guide for Kotlin 1.9.x)

_[Keeping the Language Modern](kotlin-evolution-principles.md)_ and _[Comfortable Updates](kotlin-evolution-principles.md)_ are among the fundamental principles in
Kotlin Language Design. The former says that constructs which obstruct language evolution should be removed, and the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[//]: # (title: Compatibility guide for Kotlin 2.0)
[//]: # (title: Compatibility guide for Kotlin 2.0.x)

_[Keeping the Language Modern](kotlin-evolution-principles.md)_ and _[Comfortable Updates](kotlin-evolution-principles.md)_ are among the fundamental principles in
Kotlin Language Design. The former says that constructs which obstruct language evolution should be removed, and the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[//]: # (title: Compatibility guide for Kotlin 2.1)
[//]: # (title: Compatibility guide for Kotlin 2.1.x)

_[Keeping the Language Modern](kotlin-evolution-principles.md)_ and _[Comfortable Updates](kotlin-evolution-principles.md)_ are among the fundamental principles in
Kotlin Language Design. The former says that constructs which obstruct language evolution should be removed, and the
Expand Down
8 changes: 0 additions & 8 deletions docs/topics/compatibility-guides/compatibility-modes.md

This file was deleted.

4 changes: 2 additions & 2 deletions docs/topics/competitive-programming.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ programming, Kotlin incidentally fits well in this domain, reducing the typical
programmer needs to write and read while working with the code almost to the level offered by dynamically-typed
scripting languages, while having tooling and performance of a statically-typed language.

See [Get started with Kotlin/JVM](jvm-get-started.md) on how to set up development
environment for Kotlin. In competitive programming, a single project is usually created and each problem's solution is
For more information on how to create a Kotlin project in IntelliJ IDEA, see the [Create a console app](jvm-get-started.md)
tutorial. In competitive programming, a single project is usually created and each problem's solution is
written in a single source file.

## Simple example: Reachable Numbers problem
Expand Down
2 changes: 0 additions & 2 deletions docs/topics/gradle/gradle-configure-project.md
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,6 @@ Learn more about:

### Other details

Learn more about [Kotlin/JVM](jvm-get-started.md).

#### Disable use of artifact in compilation task

In some rare scenarios, you can experience a build failure caused by a circular dependency error. For example, when you
Expand Down
2 changes: 1 addition & 1 deletion docs/topics/gradle/gradle.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ Learn about:
please refer to the [Dokka README](https://github.com/Kotlin/dokka/blob/master/README.md#using-the-gradle-plugin)
for configuration instructions. Dokka supports mixed-language projects and can generate output in multiple
formats, including standard Javadoc.
* **OSGi**. For OSGi support see the [Kotlin OSGi page](kotlin-osgi.md).
* **OSGi**. For OSGi support see the [Kotlin OSGi page](kotlin-osgi.md).
2 changes: 1 addition & 1 deletion docs/topics/home.topic
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<a href="whatsnew2220.md" summary="Important changes for web development, along with other improvements and bug fixes">What's new in Kotlin 2.2.20</a>
<a href="releases.md" summary="The latest Kotlin releases and instructions on how to update to them">Kotlin releases</a>
<a href="https://kotlinlang.org/api/latest/jvm/stdlib/" summary="Living essentials for everyday work with Kotlin: IO, files, threading, collections, and much more">Standard library API reference</a>
<a href="basic-types.md" summary="Kotlin type system: numbers, strings, arrays, and other built-in types">Basic types</a>
<a href="types-overview.md" summary="Kotlin type system: numbers, strings, arrays, and other built-in types">Types overview</a>
<a href="collections-overview.md" summary="Collections: lists, sets, and maps">Collections</a>
<a href="coroutines-overview.md" summary="Concurrency: coroutines, flows, channels">Coroutines</a>
</cards>
Expand Down
5 changes: 5 additions & 0 deletions docs/topics/inheritance.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
[//]: # (title: Inheritance)

> Before creating an inheritance hierarchy with classes, consider using [abstract classes](classes.md#abstract-classes) or [interfaces](interfaces.md).
> You can inherit from abstract classes and interfaces by default. They are designed so that other classes can inherit their members amd implement them.
>
{style="tip"}

All classes in Kotlin have a common superclass, `Any`, which is the default superclass for a class with no supertypes declared:

```kotlin
Expand Down
4 changes: 2 additions & 2 deletions docs/topics/jvm/comparison-to-java.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Kotlin fixes a series of issues that Java suffers from:
## What Java has that Kotlin does not

* [Checked exceptions](exceptions.md)
* [Primitive types](basic-types.md) that are not classes. The byte-code uses primitives where possible, but they are not
* [Primitive types](types-overview.md) that are not classes. The byte-code uses primitives where possible, but they are not
explicitly available.
* [Static members](classes.md) are replaced with [companion objects](object-declarations.md#companion-objects),
[top-level functions](functions.md), [extension functions](extensions.md#extension-functions), or [@JvmStatic](java-to-kotlin-interop.md#static-methods).
Expand All @@ -36,7 +36,7 @@ Kotlin fixes a series of issues that Java suffers from:
* [Properties](properties.md)
* [Primary constructors](classes.md)
* [First-class delegation](delegation.md)
* [Type inference for variable and property types](basic-types.md) (**Java 10**: [Local-Variable Type Inference](https://openjdk.org/jeps/286))
* [Type inference for variable and property types](types-overview.md) (**Java 10**: [Local-Variable Type Inference](https://openjdk.org/jeps/286))
* [Singletons](object-declarations.md)
* [Declaration-site variance & Type projections](generics.md)
* [Range expressions](ranges.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/topics/jvm/jvm-get-started.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[//]: # (title: Get started with Kotlin/JVM)
[//]: # (title: Create a console app – tutorial)

This tutorial demonstrates how to use IntelliJ IDEA for creating a console application.

Expand Down
9 changes: 3 additions & 6 deletions docs/topics/jvm/jvm-spring-boot-using-crudrepository.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,6 @@ Get your personal language map to help you navigate Kotlin features and track yo
<img src="get-kotlin-language-map.png" width="700" alt="Get the Kotlin language map" style="block"/>
</a>

* Learn more about [Calling Java from Kotlin code](java-interop.md) and [Calling Kotlin from Java code](java-to-kotlin-interop.md).
* Learn how to convert existing Java code to Kotlin with the [Java-to-Kotlin converter](mixing-java-kotlin-intellij.md#converting-an-existing-java-file-to-kotlin-with-j2k).
* Check out our Java to Kotlin migration guides:
* [Strings in Java and Kotlin](java-to-kotlin-idioms-strings.md).
* [Collections in Java and Kotlin](java-to-kotlin-collections-guide.md).
* [Nullability in Java and Kotlin](java-to-kotlin-nullability-guide.md).
* Check out the [Spring Framework](https://docs.spring.io/spring-framework/docs/current/reference/html/languages.html#languages) documentation.
* Complete the [Building web applications with Spring Boot and Kotlin](https://spring.io/guides/tutorials/spring-boot-kotlin) tutorial.
* Create a chat application in the [Spring Boot with Kotlin Coroutines and RSocket](https://spring.io/guides/tutorials/spring-webflux-kotlin-rsocket/) tutorial.
2 changes: 1 addition & 1 deletion docs/topics/jvm/jvm-test-using-junit.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[//]: # (title: Test code using JUnit in JVM – tutorial)
[//]: # (title: Test code using JUnit – tutorial)

This tutorial shows you how to write a simple unit test in a Kotlin/JVM project and run it with the Gradle build tool.

Expand Down
3 changes: 1 addition & 2 deletions docs/topics/jvm/mixing-java-kotlin-intellij.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

Kotlin provides the first-class interoperability with Java, and modern IDEs make it even better.
In this tutorial, you'll learn how to use both Kotlin and Java sources in the same project in
IntelliJ IDEA. To learn how to start a new Kotlin project in IntelliJ IDEA,
see [Getting started with IntelliJ IDEA](jvm-get-started.md).
IntelliJ IDEA.

## Adding Java source code to an existing Kotlin project

Expand Down
14 changes: 10 additions & 4 deletions docs/topics/kotlin-evolution-principles.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,20 @@ and even when it's over and the change ships in a stable version, there's still

### Compatibility options

We provide the `-language-version X.Y` and `-api-version X.Y` options that make a new version emulate the behavior of an old
one for compatibility purposes. To give you more time for migration, we [support](compatibility-modes.md)
the three previous language and API versions in addition to the latest stable one.
We provide compatiblity options that make a new Kotlin version emulate the behavior of an old one for compatibility purposes:

* `-language-version X.Y` - compatibility mode for Kotlin language version X.Y, reports errors for all language features
that came out later.
* `-api-version X.Y` - compatibility mode for Kotlin API version X.Y, reports errors for all code using newer APIs from
the Kotlin Standard Library (including the code generated by the compiler).

To give you more time for migration, we support the development for at least three previous language and API versions
in addition to the latest stable one.

Actively maintained code bases can benefit from getting bug fixes as soon as possible, without waiting for a full deprecation cycle to complete.
Currently, such projects can enable the `-progressive` option and get such fixes enabled even in tooling releases.

All options are available in the command line as well as in [Gradle](gradle-compiler-options.md) and in [Maven](maven.md#specify-compiler-options).
All options are available in the IDE, command line, as well as in [Gradle](gradle-compiler-options.md) and in [Maven](maven.md#specify-compiler-options).

### Evolving the binary format

Expand Down
2 changes: 1 addition & 1 deletion docs/topics/kotlin-ide.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ Also, you could use package managers, such as [Homebrew](command-line.md#homebre

## What's next?

* [Start your first project using IntelliJ IDEA IDE](jvm-get-started.md)
* [Create a console application in IntelliJ IDEA](jvm-get-started.md)
* [Create your first cross-platform mobile app using Android Studio](https://www.jetbrains.com/help/kotlin-multiplatform-dev/multiplatform-create-first-app.html)
2 changes: 1 addition & 1 deletion docs/topics/maven.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,4 +382,4 @@ your Maven project, see [Maven](dokka-maven.md).

## Enable OSGi support

[Learn how to enable OSGi support in your Maven project](kotlin-osgi.md#maven).
[Learn how to enable OSGi support in your Maven project](kotlin-osgi.md#maven).
21 changes: 19 additions & 2 deletions docs/topics/null-safety.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,9 @@ You can also place a safe call on the left side of an assignment:
person?.department?.head = managersPool.getManager()
```

In the example above, if one of the receivers in the safe call chain is `null`, the assignment is skipped, and the expression on the right is not evaluated at all. For example, if either
`person` or `person.department` is `null`, the function is not called. Here's the equivalent of the same safe call but with the `if` conditional:
In the example above, if one of the receivers in the safe call chain is `null`, the assignment is skipped, and the
expression on the right is not evaluated at all. For example, if either `person` or `person.department` is `null`, the
function is not called. Here's the equivalent of the same safe call but with the `if` conditional:

```kotlin
if (person != null && person.department != null) {
Expand Down Expand Up @@ -247,6 +248,7 @@ Instead of writing the complete `if` expression, you can handle this in a more c

```kotlin
fun main() {

//sampleStart
// Assigns null to a nullable variable
val b: String? = null
Expand All @@ -259,6 +261,21 @@ fun main() {
```
{kotlin-runnable="true"}

```kotlin
fun main() {

//sampleStart
// Assigns null to a nullable variable
val b: String? = null
// Checks for nullability. If not null, returns length. If null, returns a non-null value
val l = b?.length ?: 100
println(l)
// 0
//sampleEnd
}
```
{kotlin-runnable="true"}

If the expression to the left of `?:` is not `null`, the Elvis operator returns it. Otherwise, the Elvis operator returns the expression
to the right. The expression on the right-hand side is evaluated only if the left-hand side is `null`.

Expand Down
2 changes: 1 addition & 1 deletion docs/topics/operator-overloading.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function or an extension function.
* If the function is absent or ambiguous, it is a compilation error.
* If the function is present and its return type is `R`, the expression `+a` has type `R`.

> These operations, as well as all the others, are optimized for [basic types](basic-types.md) and do not introduce
> These operations, as well as all the others, are optimized for [basic types](types-overview.md) and do not introduce
> overhead of function calls for them.
>
{style="note"}
Expand Down
4 changes: 2 additions & 2 deletions docs/topics/properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ const val MAX_LOGIN_ATTEMPTS = 3
Compile-time constants must meet the following requirements:

* They must be either a top-level property, or a member of an [`object` declaration](object-declarations.md#object-declarations-overview) or a [companion object](object-declarations.md#companion-objects).
* They must be initialized with a value of type `String` or a [primitive type](basic-types.md).
* They must be initialized with a value of type `String` or a [primitive type](types-overview.md).
* They can't have a custom getter.

Compile-time constants still have a backing field, so you can interact with them using [reflection](reflection.md).
Expand Down Expand Up @@ -427,7 +427,7 @@ For class properties:
* You can't declare them in the primary constructor.
* They must not have a custom getter or setter.

In all cases, the property or variable must be non-nullable and must not be a [primitive type](basic-types.md).
In all cases, the property or variable must be non-nullable and must not be a [primitive type](types-overview.md).

If you access a `lateinit` property before initializing it, Kotlin throws a specific exception that identifies the uninitialized
property being accessed:
Expand Down
Loading