Kotlin (programming language): Difference between revisions

Content deleted Content added
No edit summary
Kotlin is definitely not a declarative PL
 
(635 intermediate revisions by more than 100 users not shown)
Line 1:
{{Short description|General-purpose programming language derived from Java}}
{{third-party|date=February 2018}}
{{Use dmy dates|date=July 2020}}
{{Infobox programming language
| name = Kotlin
| logo = [[File:Kotlin- logo.png|Kotlin Logo]](2021-present).svg
| paradigmlogo size = 230px
| paradigm = [[Multi-paradigm programming language|Multi-paradigm]]: [[Object-oriented programming|object-oriented]], [[Functional programming|functional]], [[Imperative programming|imperative]], [[Block (programming)|block structured]], [[Generic programming|generic]], [[Reflective programming|reflective]], [[Concurrent computing|concurrent]]
| released = 2011
| family =
| released = {{Start date and age|2011|07|22|df=y}}
| designer = [[JetBrains]]
| developer = [[JetBrains and open source contributors]]
| latest release version = Kotlin 1.2.40{{wikidata|property|reference|edit|P348}}
| latest release date = {{Start date and age|2018|04|19}}<ref>{{cite web wikidata|url = https://blog.jetbrains.com/kotlin/2018/04/kotlin-1-2-40-is-out/ qualifier|title = Kotlin 1.2.40 is out! P348|website = Kotlin Blog |date = 2018-04-19 P577}}|accessdate df= 2018-04-19 y}}</ref>
| latest preview version = <!-- 1.6.20-RC2<ref>{{Cite web |title=Releases · JetBrains/kotlin |url=https://github.com/JetBrains/kotlin/releases |access-date=2022-03-30 |website=GitHub |language=en}}</ref><ref>{{Cite web|title=Preview of Kotlin 1.6.20 With Prototype of Context Receivers, Parallel Compilation on JVM, Incremental Compilation in JS, and More {{!}} The Kotlin Blog|url=https://blog.jetbrains.com/kotlin/2022/02/kotlin-1-6-20-m1-released/|access-date=2022-02-09|website=The JetBrains Blog|language=en-US}}</ref> -->
| typing = [[Statically typed|static]], [[type inference|inferred]]
| latest preview date = {{Start date and age|2022|03|23|df=no}}
| typing = [[Type inference|Inferred]], [[static typing|static]], [[strong typing|strong]]
| implementations =
| dialects =
| platform = * [[Android (operating system)|Android]]
| influenced by = [[Java (programming language)|Java]], [[Scala (programming language)|Scala]], [[Groovy (programming language)|Groovy]], [[C Sharp (programming language)|C#]], [[Gosu (programming language)|Gosu]], [[JavaScript]]
| platform = Outputs* [[Java virtual machine]] [[Java bytecode|bytecode]] and [[JavaScript]] [[source codeJVM]]
* [[JavaScript]] ([https://kotlinlang.org/docs/js-overview.html Kotlin/JS])
| operating system = Any supporting JVM or JavaScript interpreter
<!-- rest through Kotlin/Native (in Beta) unlike above -->
| license = [[Apache license|Apache 2]]
* [[macOS]] (incl. [[Apple silicon]] support)
| file_ext = .kt, .kts, .ktm
* [[iOS]], [[tvOS]], [[watchOS]]
| website = {{URL|https://kotlinlang.org}}
* [[Linux]]
| wikibooks =
* [[Microsoft Windows|Windows]] <!-- (MinGW) -->
| caption =
* [[WebAssembly]]
* [[LLVM]] ([https://kotlinlang.org/docs/native-overview.html Kotlin/Native])
| operating system = [[Cross-platform software|Cross-platform]]
| license = [[Apache License 2.0|Apache 2.0]]
| file_ext = .kt, .kts, .kexe, .klib
| website = {{url|https://kotlinlang.org/}}
| influenced by = {{Hlist|[[C Sharp (programming language)|C#]]|[[Eiffel (programming language)|Eiffel]]|[[Gosu (programming language)|Gosu]]|[[Groovy (programming language)|Groovy]]|[[Java (programming language)|Java]]|[[JavaScript]]|[[ML (programming language)|ML]]|[[Python (programming language)|Python]]|[[Scala (programming language)|Scala]]}}
| influenced = [[V (programming language)|V (Vlang)]]
}}
 
'''Kotlin''' ({{IPAc-en|ˈ|k|ɒ|t|l|ɪ|n}})<ref name="pronunciation">{{cite web
'''Kotlin''' is a [[Statically typed|statically typed]] [[programming language]] that runs on the [[Java virtual machine]] and also can be compiled to [[JavaScript]] source code or use the [[LLVM]] compiler infrastructure. Its primary development is from a team of [[JetBrains]] programmers based in [[Saint Petersburg]], Russia.<ref name="oracle_interview">{{cite web |title = The Advent of Kotlin: A Conversation with JetBrains' Andrey Breslav |url = http://www.oracle.com/technetwork/articles/java/breslav-1932170.html |first = Janice |last = Heiss |website = oracle.com |date = April 2013 |accessdate = February 2, 2014 |publisher = Oracle Technology Network }}</ref> While the syntax is not compatible with Java, the JVM implementation of Kotlin's standard library is designed to interoperate with [[Java (programming language)|Java]] code and is reliant on Java code from the existing [[Java Class Library]], such as the [[Java collections framework|collections framework]]<ref name="kotlin_stdlib">{{cite web |title = kotlin-stdlib |url = https://kotlinlang.org/api/latest/jvm/stdlib/index.html |website=kotlinlang.org |accessdate = April 20, 2018 |publisher = JetBrains}}</ref>. Kotlin uses aggressive [[Type inference|type inference]] to determine the type of values and expressions for which type has been left unstated. This reduces language verbosity relative to Java, which demands often entirely redundant type specifications prior to version 10.
|url=https://discuss.kotlinlang.org/t/what-is-the-correct-english-pronunciation-of-kotlin/2050
|title=What is the correct English pronunciation of Kotlin?
|date=16 October 2019
|access-date=9 November 2019
|archive-date=9 November 2019
|archive-url=https://web.archive.org/web/20191109155142/https://discuss.kotlinlang.org/t/what-is-the-correct-english-pronunciation-of-kotlin/2050
|url-status=live
}}</ref> is a [[Cross-platform software|cross-platform]], [[static typing|statically typed]], [[general-purpose programming language|general-purpose]] [[High-level programming language|high-level]] [[programming language]] with [[type inference]]. Kotlin is designed to interoperate fully with [[Java (programming language)|Java]], and the [[Java virtual machine|JVM]] version of Kotlin's [[standard library]] depends on the [[Java Class Library]],<!--ref>{{cite book |last1=Saumont |first1=Pierre-Yves |year=2019 |url=https://livebook.manning.com/book/the-joy-of-kotlin/a-mixing-kotlin-with-java/v-8/ |chapter=A Mixing Kotlin with Java |title=The Joy of Kotlin |publisher=[[Manning Publications]] |url-status=live |archive-url=https://web.archive.org/web/20230623140847/https://livebook.manning.com/book/the-joy-of-kotlin/a-mixing-kotlin-with-java/v-8/ |archive-date=2023-06-23}}</ref-->
but type inference allows its [[syntax (programming languages)|syntax]] to be more concise. Kotlin mainly targets the JVM, but also compiles to [[JavaScript]] (e.g., for frontend web applications using [[React (software)|React]])<ref>{{Cite web|title=Kotlin for JavaScript - Kotlin Programming Language|url=https://kotlinlang.org/docs/reference/js-overview.html|access-date=2020-08-20|website=Kotlin|language=en|archive-date=16 August 2020|archive-url=https://web.archive.org/web/20200816160848/https://kotlinlang.org/docs/reference/js-overview.html|url-status=live}}</ref> or [[machine code|native code]] via [[LLVM]] (e.g., for native [[iOS]] apps sharing [[business logic]] with [[Android (operating system)|Android]] apps).<ref>{{Cite web|title=Kotlin for cross-platform mobile development|url=https://www.jetbrains.com/lp/mobilecrossplatform/|access-date=2020-08-20|website=JetBrains: Developer Tools for Professionals and Teams|language=en|archive-date=19 August 2020|archive-url=https://web.archive.org/web/20200819163838/https://www.jetbrains.com/lp/mobilecrossplatform/|url-status=live}}</ref> Language development costs are borne by [[JetBrains]], while the Kotlin Foundation protects the Kotlin trademark.<ref>{{Cite web|url=https://kotlinlang.org/foundation/kotlin-foundation.html|title=Kotlin Foundation - Kotlin Programming Language|website=Kotlin|access-date=16 December 2019|archive-date=29 December 2019|archive-url=https://web.archive.org/web/20191229152934/https://kotlinlang.org/foundation/kotlin-foundation.html|url-status=live}}</ref>
 
On 7 May 2019, Google announced that the Kotlin programming language had become its preferred language for [[Android (operating system)|Android]] app developers.<ref name="auto">{{cite web |last1=Lardinois |first1=Frederic |date=7 May 2019 |title=Kotlin is now Google's preferred language for Android app development |url=https://techcrunch.com/2019/05/07/kotlin-is-now-googles-preferred-language-for-android-app-development/ |access-date=8 May 2019 |website=TechCrunch |language=en-US |archive-date=7 May 2019 |archive-url=https://web.archive.org/web/20190507203145/https://techcrunch.com/2019/05/07/kotlin-is-now-googles-preferred-language-for-android-app-development/ |url-status=live}}</ref> Since the release of [[Android Studio]] 3.0 in October 2017, Kotlin has been included as an alternative to the standard Java [[compiler]]. The Android Kotlin compiler emits Java 8 [[bytecode]] by default (which runs in any later JVM), but allows targeting Java 9 up to 20, for optimizing,<ref name="kotlin-faq">{{cite web |url=https://kotlinlang.org/docs/faq.html#which-versions-of-jvm-does-kotlin-target |title=Kotlin FAQ |quote=Kotlin lets you choose the version of JVM for execution. By default, the Kotlin/JVM compiler produces Java 8 compatible bytecode. If you want to make use of optimizations available in newer versions of Java, you can explicitly specify the target Java version from 9 to 21. Note that in this case the resulting bytecode might not run on lower versions. |access-date=2024-08-20 |archive-date=2 June 2021 |archive-url=https://web.archive.org/web/20210602213318/https://kotlinlang.org/docs/faq.html#which-versions-of-jvm-does-kotlin-target |url-status=live}}</ref> or allows for more features; has bidirectional [[record (computer science)|record class]] interoperability support for JVM, introduced in Java 16, considered stable as of Kotlin 1.5.
As of [[Android Studio#Version history|Android Studio 3.0]] (October 2017) Kotlin is a fully supported programming language by [[Google]] on the [[Android (operating system)|Android Operating System]]<ref name="kotlin-android">{{cite web |url = https://blog.jetbrains.com/kotlin/2017/05/kotlin-on-android-now-official/ |title = Kotlin on Android. Now official |first = Maxim |last = Shafirov |quote = Today, at the Google I/O keynote, the Android team announced first-class support for Kotlin. |date = May 17, 2017 }}</ref>, and is directly included in the Android Studio 3.0 IDE package as an alternative to the standard Java compiler. The Android Kotlin compiler lets the user choose between targeting [[Java language|Java]] 6- or Java 8-compatible bytecode.<ref name="kotlin-faq">{{cite web |url = https://kotlinlang.org/docs/reference/faq.html
|title = Kotlin FAQ |quote = Kotlin lets you choose between generating Java 6 and Java 8 compatible bytecode. More optimal byte code may be generated for higher versions of the platform.}}</ref>
 
Kotlin has support for the web with Kotlin/JS, <!-- too much detail since deprecated: either through a classic interpreter-based backend which has been declared stable since version 1.3, or --> through an [[intermediate representation]]-based backend which has been declared stable since version 1.8, released December 2022. Kotlin/Native (for e.g. [[Apple silicon]] support<!-- might be an untrue statement since some parts are still beta since 1.3: https://kotlinlang.org/docs/native-objc-interop.html Interoperability with Swift/Objective-C "The Objective-C libraries import is Experimental." outdated docoment, or at least beta? Unclear if enough Apple support e.g. for Swift only is fully stable-->) has been declared stable since version 1.9.20, released November 2023.<ref name=stability>{{Cite web |title=Stability of Kotlin Components |url=https://kotlinlang.org/docs/components-stability.html |access-date=July 29, 2021 |date=May 21, 2021 |website=Kotlin |archive-date=29 July 2021 |archive-url=https://web.archive.org/web/20210729105608/https://kotlinlang.org/docs/components-stability.html |url-status=live}}</ref><ref name=whatsnew150>{{Cite web |title=Kotlin 1.5.0 – the First Big Release of 2021 |url=https://blog.jetbrains.com/kotlin/2021/05/kotlin-1-5-0-released/ |access-date=July 29, 2021 |date=4 May 2021 |website=Kotlin |archive-date=12 August 2021 |archive-url=https://web.archive.org/web/20210812172858/https://blog.jetbrains.com/kotlin/2021/05/kotlin-1-5-0-released/ |url-status=live}}</ref>
== History ==
In July 2011, JetBrains unveiled Project Kotlin, a new language for the JVM, which had been under development for a year.<ref name="announce">{{cite web |url = https://www.infoworld.com/d/application-development/jetbrains-readies-jvm-based-language-167875 |publisher = InfoWorld |website = infoworld.com |first = Paul |last = Krill |title = JetBrains readies JVM language Kotlin |date = Jul 22, 2011 |accessdate = February 2, 2014 }}</ref> JetBrains lead Dmitry Jemerov said that most languages did not have the features they were looking for, with the exception of [[Scala (programming language)|Scala]]. However, he cited the slow compile time of Scala as an obvious deficiency.<ref name="announce"/> One of the stated goals of Kotlin is to compile as quickly as Java. In February 2012, JetBrains open sourced the project under the [[Apache license|Apache 2 license]].<ref name="open source">{{cite web |url = https://adtmag.com/articles/2012/02/22/kotlin-goes-open-source.aspx |title = Kotlin Goes Open Source |first = John |last = Waters |date = February 22, 2012 |accessdate = February 2, 2014 |website = ADTmag.com/ |publisher = 1105 Enterprise Computing Group }}</ref>
 
==History==
The name comes from [[Kotlin Island]], near St. Petersburg. [[Andrey Breslav]] mentioned that the team decided to name it after an island just like Java was named after the Indonesian island of [[Java]]<ref>{{Citation |last = Mobius |title = Андрей Бреслав — Kotlin для Android: коротко и ясно |date = 2015-01-08 |url = https://www.youtube.com/watch?v=VU_L2_XGQ9s |accessdate = 2017-05-28 }}</ref> (though the programming language Java was perhaps named after the coffee.<ref>https://www.javaworld.com/article/2077265/core-java/so-why-did-they-decide-to-call-it-java-.html</ref>)
[[File:Kodee-mascot-regular.svg|thumb|upright=0.5|Kotlin mascot named Kodee (regular version)]]
[[File:Kodee-mascot-petite.svg|thumb|upright=0.5|Kotlin mascot named Kodee (petite version)]]
 
=== Name ===
JetBrains hopes that the new language will drive [[IntelliJ IDEA]] sales.<ref>{{cite web |url = https://blog.jetbrains.com/kotlin/2011/08/why-jetbrains-needs-kotlin/ |title = Why JetBrains needs Kotlin |quote = we expect Kotlin to drive the sales of IntelliJ IDEA }}</ref>
The name is derived from [[Kotlin Island]], a Russian island in the [[Gulf of Finland]], near [[Saint Petersburg]]. Andrey Breslav, Kotlin's former lead designer, mentioned that the team decided to name it after an island, in imitation of the Java programming language which shares a name with the Indonesian island of [[Java]].<ref>{{Citation |last1=Mobius |title=Андрей Бреслав – Kotlin для Android: коротко и ясно |date=8 January 2015 |url=https://www.youtube.com/watch?v=VU_L2_XGQ9s |access-date=28 May 2017 |archive-date=12 April 2023 |archive-url=https://web.archive.org/web/20230412075657/https://www.youtube.com/watch?v=VU_L2_XGQ9s |url-status=live}}</ref>
 
=== Development ===
Kotlin v1.0 was released on February 15, 2016.<ref>{{cite web |url = https://blog.jetbrains.com/kotlin/2016/02/kotlin-1-0-released-pragmatic-language-for-jvm-and-android/ |title = Kotlin 1.0 Released: Pragmatic Language for JVM and Android &#124; Kotlin Blog |website = Blog.jetbrains.com |date = 2016-02-15 |accessdate = 2017-04-11 }}</ref> This is considered to be the first officially stable release and JetBrains has committed to long-term backwards compatibility starting with this version.
The first commit to the Kotlin Git repository was on 8 November 2010.<ref>{{Cite web |title=test · JetBrains/kotlin@3e4dce3 |url=https://github.com/JetBrains/kotlin/commit/3e4dce385331c91c9059fcdcea3eae2394f34942 |access-date=2022-10-17 |website=GitHub |language=en |archive-date=17 October 2022 |archive-url=https://web.archive.org/web/20221017184043/https://github.com/JetBrains/kotlin/commit/3e4dce385331c91c9059fcdcea3eae2394f34942 |url-status=live}}</ref>
 
In July 2011, [[JetBrains]] unveiled Project Kotlin, a new language for the JVM, which had been under development for a year.<ref name="announce">{{cite news |last1=Krill |first1=Paul |date=22 July 2011 |url=https://www.infoworld.com/d/application-development/jetbrains-readies-jvm-based-language-167875 |title=JetBrains readies JVM language Kotlin |work=[[InfoWorld]] |access-date=2 February 2014 |archive-url=https://web.archive.org/web/20190907161741/https://www.infoworld.com/article/2622405/jetbrains-readies-jvm-based-language.html |archive-date=7 September 2019 |url-status=live}}</ref> JetBrains lead Dmitry Jemerov said that most languages did not have the features they were looking for, with the exception of [[Scala (programming language)|Scala]]. However, he cited the slow [[compiler|compilation]] time of Scala as a deficiency.<ref name="announce" /> One of the stated goals of Kotlin is to compile as quickly as Java. In February 2012, JetBrains open sourced the project under the [[Apache License#Apache License 2.0|Apache 2 license]].<ref name="open source">{{cite news |last1=Waters |first1=John |date=22 February 2012 |url=https://adtmag.com/articles/2012/02/22/kotlin-goes-open-source.aspx |title=Kotlin Goes Open Source |website=ADTmag.com |publisher=1105 Enterprise Computing Group |url-status=live |archive-url=https://web.archive.org/web/20140218225151/https://adtmag.com/articles/2012/02/22/kotlin-goes-open-source.aspx |archive-date=18 February 2014 |access-date=2 February 2014}}</ref>
At [[Google I/O]] 2017, [[Google]] announced first-class support for Kotlin on [[Android (operating system)|Android]].<ref name="kotlin-android"/>
 
KotlinJetBrains v1.2expected wasKotlin releasedto ondrive November[[IntelliJ 28,IDEA]] 2017sales.<ref>{{cite web |url = https://blog.jetbrains.com/kotlin/20172011/1108/kotlinwhy-1jetbrains-2needs-releasedkotlin/ |title =Why JetBrains needs Kotlin 1.|date=2 Released:August Sharing2011 Code|access-date=11 between Platforms &#124; KotlinFebruary Blog2018 |website url-status=live Blog|archive-url=https://web.archive.org/web/20230816024048/https://blog.jetbrains.com/kotlin/2011/08/why-jetbrains-needs-kotlin/ |archive-date =16 2017-11-28August }}</ref>2023 Sharing|quote=we Codeexpect betweenKotlin JVMto anddrive Javascriptthe platformssales featureof wasIntelliJ newly added to this release.IDEA}}</ref>
 
Kotlin 1.0 was released on 15 February 2016.<ref>{{cite web |url=https://blog.jetbrains.com/kotlin/2016/02/kotlin-1-0-released-pragmatic-language-for-jvm-and-android/ |title=Kotlin 1.0 Released: Pragmatic Language for JVM and Android &#124; Kotlin Blog |website=Blog.jetbrains.com |date=15 February 2016 |access-date=11 April 2017 |archive-date=24 January 2018 |archive-url=https://web.archive.org/web/20180124194203/https://blog.jetbrains.com/kotlin/2016/02/kotlin-1-0-released-pragmatic-language-for-jvm-and-android/ |url-status=live}}</ref> This is considered to be the first officially stable release and JetBrains has committed to long-term backwards compatibility starting with this version.
== Philosophy ==
Development lead [[Andrey Breslav]] has said that Kotlin is designed to be an industrial-strength [[object oriented programming|object-oriented]] language, and a "better language" than Java, but still be fully interoperable with Java code, allowing companies to make a gradual migration from Java to Kotlin.<ref name="interview">{{cite web |title = JVM Languages Report extended interview with Kotlin creator Andrey Breslav |url = https://zeroturnaround.com/rebellabs/jvm-languages-report-extended-interview-with-kotlin-creator-andrey-breslav/ |website = Zeroturnaround.com |date = April 22, 2013 |accessdate = February 2, 2014 }}</ref>
 
At [[Google I/O]] 2017, Google announced first-class support for Kotlin on [[Android (operating system)|Android]].<ref name="kotlin-android">{{cite news |last1=Shafirov |first1=Maxim |date=17 May 2017 |url=https://blog.jetbrains.com/kotlin/2017/05/kotlin-on-android-now-official/ |title=Kotlin on Android. Now official |quote=Today, at the Google I/O keynote, the Android team announced first-class support for Kotlin. |access-date=18 May 2017 |url-status=live |archive-url=https://web.archive.org/web/20230529180054/https://blog.jetbrains.com/kotlin/2017/05/kotlin-on-android-now-official/ |archive-date=29 May 2023}}</ref> On 7 May 2019, Google announced that the Kotlin programming language is now its preferred language for Android app developers.<ref name="auto"/>
[[Semicolon]]s are optional as a [[Statement (computer science)|statement]] [[Statement terminator#Statements|terminator]]; in most cases a [[newline]] is sufficient for the [[compiler]] to deduce that the statement has ended.<ref>{{cite web |url = https://confluence.jetbrains.com/display/Kotlin/Grammar#Grammar-Semicolons |title = Semicolons |website = jetbrains.com |accessdate = February 8, 2014 }}</ref>
 
==Design==
Kotlin [[Variable (computer science)|variable]] declarations and [[Parameter (computer programming)|parameter lists]] have the [[data type]] come after the variable name (and with a [[Colon (punctuation)|colon]] separator), similar to [[Pascal (programming language)|Pascal]].
Development lead Andrey Breslav has said that Kotlin is designed to be an industrial-strength [[object-oriented programming|object-oriented]] language, and a "better language" than [[Java (programming language)|Java]], but still be fully [[Interoperability|interoperable]] with Java code, allowing companies to make a gradual migration from Java to Kotlin.<ref name="interview">{{cite news |title=JVM Languages Report extended interview with Kotlin creator Andrey Breslav |url=https://zeroturnaround.com/rebellabs/jvm-languages-report-extended-interview-with-kotlin-creator-andrey-breslav/ |website=Zeroturnaround.com |date=22 April 2013 |access-date=2 February 2014 |archive-date=15 January 2019 |archive-url=https://web.archive.org/web/20190115182139/https://zeroturnaround.com/rebellabs/jvm-languages-report-extended-interview-with-kotlin-creator-andrey-breslav/ |url-status=live}}</ref>
 
[[Semicolon]]s are optional as a [[Statement (computer science)|statement]] [[Statement terminator#Statements|terminator]]; in most cases a [[newline]] is sufficient for the [[compiler]] to deduce that the statement has ended.<ref>{{cite web |url=https://confluence.jetbrains.com/display/Kotlin/Grammar#Grammar-Semicolons |title=Semicolons |website=jetbrains.com |access-date=8 February 2014 |archive-date=23 December 2015 |archive-url=https://web.archive.org/web/20151223142747/https://confluence.jetbrains.com/display/Kotlin/Grammar#Grammar-Semicolons |url-status=live}}</ref>
Variables in Kotlin can be [[immutable]], declared with the {{mono|val}} keyword or mutable, declared with the {{mono|var}} keyword. <ref>{{cite web|title=Basic Syntax|url=https://kotlinlang.org/docs/reference/basic-syntax.html#defining-variables|website=Kotlin|publisher=Jetbrains|accessdate=19 January 2018}}</ref>
 
Kotlin [[Variable (computer science)|variable]] declarations and [[Parameter (computer programming)|parameter lists]] have the [[data type]] come after the variable name (and with a [[Colon (punctuation)|colon]] separator), similar to [[Ada (programming language)|Ada]], [[BASIC]], [[Pascal (programming language)|Pascal]], [[TypeScript]] and [[Rust (programming language)|Rust]]. This, according to an article from Roman Elizarov, current project lead, results in alignment of variable names and is more pleasing to eyes, especially when there are a few variable declarations in succession, and one or more of the types is too complex for type inference, or needs to be declared explicitly for human readers to understand.<ref>{{cite web|title=Types are moving to the right|url=https://elizarov.medium.com/types-are-moving-to-the-right-22c0ef31dd4a#:~:text=Woot!%20That%E2%80%99s%20nice%20and%20aligns,%20pleasure%20for%20our%20eyes%20to%20see.|website=Medium|date=16 July 2020|access-date=6 November 2021|archive-date=22 May 2023|archive-url=https://web.archive.org/web/20230522024640/https://elizarov.medium.com/types-are-moving-to-the-right-22c0ef31dd4a#:~:text=Woot!%20That%E2%80%99s%20nice%20and%20aligns,%20pleasure%20for%20our%20eyes%20to%20see.|url-status=live}}</ref><ref>{{cite web|title=Roman Elizarov is the new Project Lead for Kotlin|url=https://blog.jetbrains.com/kotlin/2020/11/roman-elizarov-is-the-new-project-lead-for-kotlin/|website=The Kotlin Blog|date=19 November 2020|publisher=JetBrains|access-date=7 November 2021|archive-date=20 January 2022|archive-url=https://web.archive.org/web/20220120205530/https://blog.jetbrains.com/kotlin/2020/11/roman-elizarov-is-the-new-project-lead-for-kotlin/|url-status=live}}</ref>
Class members are public by default, and the classes themselves are sealed by default meaning that creating a derived class is disabled unless explicit keywords in the base class are present to enable it.
 
InThe additioninfluence to theof [[ClassScala (computer programming)|classes]] and [[Method (computer programminglanguage)|methodsScala]] (called member functions in Kotlin) ofcan [[object-orientedbe programming]],seen Kotlinin alsothe supportsextensive [[proceduralsupport programming]]for withboth theobject-oriented useand offunctional [[function (computer science)|functions]].programming<ref>{{cite web |url = https://confluence.jetbrains.com/display/Kotlin/Functions |title = functions |website = jetbrains.com |accessdate access-date=8 February 8, 2014 |archive-date=23 November 2015 |archive-url=https://web.archive.org/web/20151123112725/https://confluence.jetbrains.com/display/Kotlin/Functions |url-status=live}}</ref> and in a number of specific features:
* there is a distinction between [[Immutable object|mutable and immutable]] variables (''var'' vs ''val'' keyword)
* all classes are public and final (non-inheritable) by default
* functions and methods support [[default argument]]s, [[variadic function|variable-length argument]] lists and [[Named parameter|named argument]]s
 
Kotlin 1.3 added support for contracts,<ref>{{Cite web|url=https://kotlinlang.org/docs/reference/whatsnew13.html|title=What's New in Kotlin 1.3 - Kotlin Programming Language|website=Kotlin|access-date=4 April 2020|archive-date=22 August 2023|archive-url=https://web.archive.org/web/20230822164600/https://kotlinlang.org/docs/reference/whatsnew13.html|url-status=live}}</ref> which are stable for the standard library declarations, but still experimental for user-defined declarations. Contracts are inspired by [[Eiffel (programming language)|Eiffel's]] [[design by contract]]<ref>{{Cite web|url=https://discuss.kotlinlang.org/t/design-by-contract-dbc-design-considerations/1321|title=Design by Contract (DbC) design considerations|quote=Implement the full semantics of Eiffel DbC and improve upon it.|date=16 August 2012|website=Kotlin Discussions|language=en-US|access-date=4 April 2020|archive-date=5 April 2023|archive-url=https://web.archive.org/web/20230405081654/https://discuss.kotlinlang.org/t/design-by-contract-dbc-design-considerations/1321|url-status=live}}</ref> [[programming paradigm]].
== Syntax ==
 
Following [https://www.scala-js.org/ ScalaJS], Kotlin code may be [[Source-to-source compiler|transpiled]] to [[JavaScript]], allowing for interoperability between code written in the two languages. This can be used either to write full web applications in Kotlin, or to share code between a Kotlin backend and a JavaScript frontend.<ref>{{Cite web|title=Kotlin for JavaScript {{!}} Kotlin|url=https://kotlinlang.org/docs/js-overview.html#use-cases-for-kotlin-js|date=21 January 2021<!-- 11 February 2021 -->|access-date=2021-03-19|website=Kotlin Help|language=en-US|archive-date=14 July 2023|archive-url=https://web.archive.org/web/20230714143003/https://kotlinlang.org/docs/js-overview.html#use-cases-for-kotlin-js|url-status=live}}</ref>
=== Functional Programming Style ===
 
==Syntax==
Kotlin relaxes Java's restriction of allowing Static Methods and variables inside of only a class body. Instead, Kotlin allows definition of static Objects and Functions at the top-level of the Package body without needing a redundant class level; similar to languages such as C or Pascal. For backwards compatibility with Java, Kotlin adds a special attribute to a Kotlin package body that specifies a Java class name for nesting toplevel static functions and variables when the Kotlin package is viewed from a Java project. (ie. @file:JvmName("JavaClassName")).
 
===MainProcedural Entryprogramming Pointstyle===
Kotlin relaxes Java's restriction of allowing [[Static (keyword)|static]] methods and variables to exist only within a class body. Static objects and functions can be defined at the top level of the package without needing a redundant class level. For compatibility with Java, Kotlin provides a <code>JvmName</code> annotation which specifies a class name used when the package is viewed from a Java project. For example, <code>@file:JvmName("JavaClassName")</code>.
As in C and C++, the [[entry point]] to a Kotlin [[Computer program|program]] is a function named "main", which is passed an array containing any [[Command-line interface|command line]] arguments. [[Perl]] and Unix/Linux [[shell script]]-style [[string interpolation]] is supported. [[Type inference]] is also supported.
 
===Main entry point===
{{Main|Entry point}}
 
As in [[C (programming language)|C]], [[C++]], [[C Sharp (programming language)|C#]], Java, and [[Go (programming language)|Go]], the [[entry point]] to a Kotlin [[Computer program|program]] is a function named "main", which may be passed an array containing any [[Command-line interface|command-line]] arguments. This is optional since Kotlin 1.3.<ref>{{cite web |url=https://play.kotlinlang.org/byExample/01_introduction/01_Hello%20world |title=Kotlin Examples: Learn Kotlin Programming By Example |access-date=13 April 2019 |archive-date=18 November 2021 |archive-url=https://web.archive.org/web/20211118223052/https://play.kotlinlang.org/byExample/01_introduction/01_Hello%20world |url-status=dead}}</ref> [[Perl]], [[PHP]], and [[Unix shell]]–style [[string interpolation]] is supported. [[Type inference]] is also supported.
 
<syntaxhighlight lang="kotlin" line="1">
 
// Hello, worldWorld! example
fun main() {
val scope = "World"
println("Hello, $scope!")
}
</syntaxhighlight>
 
<syntaxhighlight lang="kotlin" line="1">
fun main(args: Array<String>) {
for (arg in args)
val scope = "world"
println("Hello, $scope!"arg)
}
</syntaxhighlight>
 
===Extension Methodsfunctions===
Similar to C#, Kotlin allows adding an [[Extension method|extension function]] to any class without the formalities of creating a derived class with new functions. An extension function has access to all the public interface of a class, which it can use to create a new function interface to a target class. An extension function will appear exactly like a function of the class and will be shown in code completion inspection of class functions. For example:
 
Similar to C#, Kotlin allows a user to add methods to any class without the formalities of creating a derived classes with new methods. Instead, Kotlin adds the concept of an extension method which allows a function to be "glued" onto the public method list of any class without being formally placed inside of the class. In other words, an extension method is a helper method that has access to all the public interface of a class which it can use to create a new method interface to a target class and this method will appear exactly like a method of the class, appearing as part of intellisense inspection of class methods: For example:
 
<syntaxhighlight lang="kotlin" line="1">
package com.example.myStringExtensions
package MyStringExtensions
 
fun String.lastChar(): Char = this.get(this.length - 1)
 
>>> println("Kotlin".lastChar())
n
</syntaxhighlight>
 
By placing the preceding code in the top-level of a package, the String class is extended to include a {{code|lastChar}} methodfunction that was not included in the original definition of the String class.
 
<syntaxhighlight lang="kotlin" line="1">
// overloadingOverloading '+' operator using an extension methodfunction
operator fun Point.plus(other: Point): Point {
return Point(x + other.x, y + other.y)
}
}
 
>>> val p1 = Point(10, 20)
>>> val p2 = Point(30, 40)
>>> println(p1 + p2)
Point(x=40, y=60)
</syntaxhighlight>
 
===Scope functions===
===Unpack Arguments with Spread Operator===
Kotlin has five scope functions, which allow the changing of [[Scope (computer science)|scope]] within the context of an [[Object (computer science)|object]]. The scope functions are {{code|let}}, {{code|run}}, {{code|with}}, {{code|apply}}, and {{code|also}}.<ref>{{Cite web |title=Scope functions {{!}} Kotlin |url=https://kotlinlang.org/docs/scope-functions.html |access-date=2024-08-10 |website=Kotlin Help |language=en-US}}</ref>
 
===Unpack arguments with spread operator===
Similar to Python, the Spread operator asterisk (*) unpacks an array's contents as comma-separated arguments to a function:
Similar to Python, the spread operator asterisk (*) unpacks an array's contents as individual arguments to a function, e.g.:
 
<syntaxhighlight lang="kotlin" line="1">
fun main(args: Array<String>) {
val list = listOf("args: ", *args)
println(list)
}
}
</syntaxhighlight>
 
===DeconstructorDestructuring Methodsdeclarations===
{{Distinguish|Destructor (computer programming)|text=the [[Destructor (computer programming)|destructor]] method common in object-oriented languages}}
''Destructuring declarations'' decompose an object into multiple variables at once, e.g. a 2D coordinate object might be ''destructured'' into two integers, {{Var|x}} and {{Var|y}}.
 
For example, the {{Code|code=Map.Entry}} object supports destructuring to simplify access to its key and value fields:
A deconstructor's job is to decompose a class object into a tuple of elemental objects. For example a 2D coordinate class might be deconstructed into a tuple of integer x and integer y. (Note: This feature is NOT to be confused with the similarly sounding destructor method that is common in object orient programming).
 
For Example, the collection object contains a deconstructor method that splits each collection item into an index and an element variable:
 
<syntaxhighlight lang="kotlin" line="1">
for ((indexkey, elementvalue) in collection.withIndex(map)) {
println("$indexkey: $elementvalue")
}
</syntaxhighlight>
 
===Nested Functionsfunctions===
 
Kotlin allows local functions to be declared inside of other functions or methods.
 
<syntaxhighlight lang="kotlin" line="1">
class User(val id: Int, val name: String, val address: String)
class User(
val id: Int,
fun saveUserToDb(user: User) {
val name: String,
fun validate(user: User, value: valString, addressfieldName: String) {
require(value.isNotEmpty()) { "Can't save user ${user.id}: empty $fieldName" }
{
 
fun saveUser(user: User) {
fun validate(user: User, value: String, fieldName: String) {
if (value.isEmpty()) {
throw IllegalArgumentException(
"Can't save user ${user.id}: empty $fieldName")
}
}
 
validate(user, user.name, "Name")
validate(user, user.address, "Address")
// Save user to the database
}
}
validate(user, user.name, "Name")
validate(user, user.address, "Address")
// Save user to the database
...
}
</syntaxhighlight>
 
===Classes are final by Defaultdefault===
In Kotlin, to derive a new class from a base class type, the base class needs to be explicitly marked as "open". This is in contrast to most object-oriented languages such as Java where classes are open by default.
 
Example of a base class that is open to deriving a new subclass from it:
In Kotlin if you want to derive a new class from a base class type, then this class needs to be explicitly marked as "open" in order to allow this to happen. This is in contrast to most object oriented languages such as Java where classes are open by default.
 
Example of a base class that is open to deriving a new subclass from it.
 
<syntaxhighlight lang="kotlin" line="1">
// open on the class means this class will allow derived classes
open class MegaButton {
 
// no-open on a function means that
// polymorphic behavior disabled if function overridden in derived class
fun disable() { ... }
 
// open on a function means that
// polymorphic behavior allowed if function is overridden in derived class
open fun animate() { ... }
}
}
 
class GigaButton: MegaButton() {
 
// Explicit use of override keyword required to override a function in derived class
override fun animate() { println("Giga Click!") }
}
}
 
</syntaxhighlight>
 
===Abstract Classesclasses are Openopen by Defaultdefault===
{{Main|Abstract class}}
[[Abstract class]]es define abstract or "pure virtual" placeholder functions that will be defined in a derived class. Abstract classes are open by default.
 
<syntaxhighlight lang="kotlin" line="1">
Abstract classes define abstract or "Pure Virtual" placeholder function that will be defined in a derived class. Abstract classes are open by default.
// No need for the open keyword here, it’s already open by default
 
abstract class Animated {
<syntaxhighlight lang="kotlin" line="1">
// No need for the open keyword here, its already open by default
abstract class Animated {
 
// This virtual function is already open by default as well
abstract fun animate()
open fun stopAnimating() { }
 
fun animateTwice() { }
}
}
</syntaxhighlight>
 
=== Classes are Publicpublic by default===
Kotlin provides the following keywords to restrict visibility for top-level declaration, such as classes, and for class members: <code>public</code>, <code>internal</code>, <code>protected</code>, and <code>private</code>.
 
When applied to a class member:
Kotlin provides the following keywords to restrict visibility for top-level declaration, such as classes, and for class members:
{| class="wikitable"
public, internal, protected, and private.
! Keyword !! Visibility
|-
| <code>public</code> (default) || Everywhere
|-
| <code>internal</code> || Within a module
|-
| <code>protected</code> || Within subclasses
|-
| <code>private</code> || Within a class
|}
 
When applied to a Classtop-level Memberdeclaration:
{| class="wikitable"
public (default): Visible everywhere
! Keyword !! Visibility
internal: Visible in a module
|-
protected: Visible in subclasses
| <code>public</code> (default) || Everywhere
private: Visible in a class
|-
 
| <code>internal</code> || Within a module
When applied to a Top-level declaration
|-
public (default): Visible everywhere
| <code>private</code> || Within a file
internal: Visible in a module
|}
private: Visible in a file
 
Example:
 
<syntaxhighlight lang="kotlin" line="1">
// Class is visible only to current module
internal open class TalkativeButton : Focusable {
// method is only visible to current class
private fun yell() = println("Hey!")
// method is visible to current class and derived classes
protected fun whisper() = println("Let's talk!")
}
internal class MyTalkativeButton: TalkativeButton() {
fun utter() = super.whisper()
}
MyTalkativeButton().utter()
</syntaxhighlight>
 
===Primary constructor vs. secondary constructors===
// method is visible to current class and derived classes
Kotlin supports the specification of a "primary constructor" as part of the class definition itself, consisting of an argument list following the class name. This argument list supports an expanded syntax on Kotlin's standard function argument lists that enables declaration of class properties in the primary constructor, including visibility, extensibility, and mutability attributes. Additionally, when defining a subclass, properties in super-interfaces and super-classes can be overridden in the primary constructor.
protected fun whisper() = println("Let's talk!")
}
</syntaxhighlight>
 
<syntaxhighlight lang="kotlin" line="1">
=== Primary Constructor vs. Secondary Constructors ===
// Example of class using primary constructor syntax
// (Only one constructor required for this class)
open class BaseUser(open var isSubscribed: Boolean)
open class PowerUser(protected val nickname: String, final override var isSubscribed: Boolean = true):BaseUser(isSubscribed) { }
</syntaxhighlight>
 
However, in cases where more than one constructor is needed for a class, a more general constructor can be defined using '''secondary constructor syntax''', which closely resembles the constructor syntax used in most object-oriented languages like C++, C#, and Java.
Most classes in Kotlin are created using only '''Primary constructor syntax''' which allows only one primary constructor. The ability to selectively choose which of the constructor properties to initialize is based on keyword selection of the property during object creation. Non-initialized constructor properties are simply set to a default value.
<syntaxhighlight lang="kotlin" line="1">
// Example of class using Primary Constructor Syntax
// (Only one constructor required for this class)
class User(
val nickname: String,
val isSubscribed: Boolean = true)
{
...
}
</syntaxhighlight>
 
<syntaxhighlight lang="kotlin" line="1">
However, in cases where more than one constructor is needed for a class, a more general constructor can be used called '''Secondary Constructor Syntax''' which closely resembles the constructor syntax used in most object-oriented langues like C++, C#, and Java.
// Example of class using secondary constructor syntax
// (more than one constructor required for this class)
class Context
class AttributeSet
open class View(ctx:Context) {
constructor(ctx: Context, attr: AttributeSet): this(ctx)
}
class MyButton : View {
// Constructor #1
constructor(ctx: Context) : super(ctx) {
}
// Constructor #2
constructor(ctx: Context, attr: AttributeSet) : super(ctx, attr) {
// ...
}
}
</syntaxhighlight>
 
===Sealed classes===
<syntaxhighlight lang="kotlin" line="1">
'''Sealed''' classes and interfaces restrict subclass hierarchies, meaning more control over the inheritance hierarchy.
// Example of class using Secondary Constructor Syntax
// (More than one constructor required for this class)
class MyButton : View {
 
Declaration of sealed interface and class:
// Constructor #1
constructor(ctx: Context) : super(ctx) {
// ...
}
// Constructor #2
constructor(ctx: Context, attr: AttributeSet) : super(ctx, attr) {
// ...
}
}
</syntaxhighlight>
 
<syntaxhighlight lang="kotlin" line="1">
=== Anko Library===
sealed interface Expr
sealed class Job
</syntaxhighlight>
All the subclasses of the sealed class are defined at compile time.
No new subclasses can be added to it after the compilation of the module having the sealed class.
For example, a sealed class in a compiled jar file cannot be subclassed.
 
<syntaxhighlight lang="kotlin" line="1">
Anko is a library specifically created for Kotlin to help build [[Android (Operating System) | Android]] UI applications.<ref>[https://github.com/Kotlin/anko Anko Github]</ref>
sealed class Vehicle
data class Car(val brandName: String, val owner: String, val color: String): Vehicle()
class Bike(val brandName: String, val owner: String, val color: String): Vehicle()
class Tractor(val brandName: String, val owner: String, val color: String): Vehicle()
val kiaCar = Car("KIA", "John", "Blue")
val hyundaiCar = Car("Hyundai", "Britto", "Green")
 
</syntaxhighlight lang="kotlin" line="1">
fun Activity.showAreYouSureAlert(process: () -> Unit) {
alert(
title = "Are you sure?",
message = "Are you really sure?")
{
positiveButton("Yes") { process() }
negativeButton("No") { cancel() }
}
}
</syntaxhighlight>
 
===KotlinData Interactive Shellclasses===
Kotlin's <code>data class</code> construct defines classes whose primary purpose is storing data, similar to Java's <code>record</code> types. Like Java's <code>record</code> types, the construct is similar to normal classes except that the key methods <code>equals</code>, <code>hashCode</code> and <code>toString</code> are automatically generated from the class properties. Unlike Java's records, data classes are open for inheritance.
 
===Kotlin interactive shell===
<syntaxhighlight lang="bash">
<syntaxhighlight lang="pycon">
$ kotlinc-jvm
type :help for help; :quit for quit
>>> 2 + 2
4
>>> println("WelcomeHello, to the Kotlin ShellWorld!")
Hello, World!
Welcome to the Kotlin Shell
>>>
</syntaxhighlight>
 
===Kotlin as a scripting Languagelanguage===
Kotlin can also be used as a [[scripting language]]. A script is a Kotlin source file using the {{mono |.kts}} [[filename extension]], with executable source code at the top-level scope:
 
Kotlin can also be used as a scripting language. A script is a Kotlin source file (.kts) with top level executable code.
 
<syntaxhighlight lang="kotlin" line="1">
Line 289 ⟶ 337:
import java.io.File
val folders = File(args[0]).listFiles { file -> file.isDirectory() }
folders?.forEach { folder -> println(folder::println) }
</syntaxhighlight>
 
ToScripts runcan abe script,run weby just passpassing the <code>-script</code> option toand the compilercorresponding withscript thefile correspondingto scriptthe filecompiler.
 
<syntaxhighlight lang="bash" line="1">
$ kotlinc -script list_folders.kts "path_to_folder_to_inspect"
</syntaxhighlight>
 
===Null safety===
'''Kotlin features in a hello world example'''
Kotlin makes a distinction between [[nullable]] and non-nullable data types. All nullable objects must be declared with a "?" postfix after the type name. Operations on nullable objects need special care from developers: a null-check must be performed before using the value, either explicitly, or with the aid of Kotlin's null-safe operators:
<syntaxhighlight lang="kotlin" line="1">
 
* {{mono|?.}} (the [[safe navigation operator]]) can be used to safely access a method or property of a possibly null object. If the object is null, the method will not be called and the expression evaluates to null. Example:
fun main(args: Array<String>) {
greet {
to.place
}.print()
}
 
{{blockquote |
//inline higher-order functions
<syntaxhighlight lang="kotlin" line="1">
inline fun greet(s: () -> String) : String = greeting andAnother s()
// returns null if...
 
// - foo() returns null,
//infix functions, extensions, type inference, nullable types, lambda expressions, labeled this, elvis operator
// - or if foo() is non-null, but bar() returns null,
infix fun String.andAnother(other : Any?) = buildString() { append(this@andAnother); append(" "); append(other ?: "") }
// - or if foo() and bar() are non-null, but baz() returns null.
 
// vice versa, return value is non-null if and only if foo(), bar() and baz() are non-null
//immutable types, delegated properties, lazy initialization, string templates
foo()?.bar()?.baz()
val greeting by lazy { val doubleEl: String = "ll"; "he${doubleEl}o" }
 
//sealed classes, companion objects
sealed class to { companion object { val place = "world"} }
 
//extensions, Unit
fun String.print() = println(this)
</syntaxhighlight>
}}
 
* {{mono|?:}} (the [[null coalescing operator]]) is a binary operator that returns the first operand, if non-null, else the second operand. It is often referred to as the [[Elvis operator]], due to its resemblance to an [[emoticon]] representation of Elvis Presley.
Variables in Kotlin can be [[immutable]], declared with the {{mono|val}} keyword or mutable, declared with the {{mono|var}} keyword. <ref>{{cite web|title=Basic Syntax|url=https://kotlinlang.org/docs/reference/basic-syntax.html#defining-variables|website=Kotlin|publisher=Jetbrains|accessdate=19 January 2018}}</ref>
 
{{blockquote |
Kotlin makes a distinction between nullable and non-nullable data types. All nullable objects must be declared with a "?" postfix after the type name. Operations on nullable objects need special care from developers: null-check must be performed before using the value. Kotlin provides null-safe operators to help developers:
<syntaxhighlight lang="kotlin" line="1">
* {{mono|?.}} ([[safe navigation operator]]) can be used to safely access a method or property of a possibly null object. If the object is null, the method will not be called and the expression evaluates to null.
* {{mono|?:}} ([[null coalescing operator]]) often referred to as the [[Elvis operator]]:
 
<syntaxhighlight lang=kotlin>
fun sayHello(maybe: String?, neverNull: Int) {
// use of elvisElvis operator
val name: String = maybe ?: "stranger"
println("Hello $name")
}
</syntaxhighlight>
}}
 
===Lambdas===
An example of the use of the safe navigation operator:
Kotlin provides support for [[higher-order function]]s and [[anonymous functions]], or '''lambdas'''.<ref>{{cite web|title=Higher-Order Functions and Lambdas|url=https://kotlinlang.org/docs/reference/lambdas.html|website=Kotlin|publisher=Jetbrains|access-date=19 January 2018|archive-date=22 January 2021|archive-url=https://web.archive.org/web/20210122222128/https://kotlinlang.org/docs/reference/lambdas.html|url-status=live}}</ref>
<syntaxhighlight lang=kotlin>
 
// returns null if...
<syntaxhighlight lang="kotlin" line="1">
// - foo() returns null,
// the following function takes a lambda, f, and executes f passing it the string "lambda"
// - or if foo() is non-null, but bar() returns null,
// note that (String) -> Unit indicates a lambda with a String parameter and Unit return type
// - or if foo() and bar() are non-null, but baz() returns null.
fun executeLambda(f: (String) -> Unit) {
// vice versa, return value is non-null if and only if foo(), bar() and baz() are non-null
f("lambda")
foo()?.bar()?.baz()
}
</syntaxhighlight>
 
Lambdas are declared using braces, {{mono|{ }<nowiki/>}}. If a lambda takes parameters, they are declared within the braces and followed by the {{mono|->}} operator.
Kotlin provides support for [[higher order functions]] and [[Anonymous functions]] or lambdas. <ref>{{cite web|title=Higher-Order Functions and Lambdas|url=https://kotlinlang.org/docs/reference/lambdas.html|website=Kotlin|publisher=Jetbrains|accessdate=19 January 2018}}</ref>
 
<syntaxhighlight lang="kotlin" line="1">
// the following functionstatement takesdefines a lambda, f,that andtakes executesa fsingle passingparameter and passes it to the string,println "lambda"function
val l = { c : Any? -> println(c) }
// note that (s: String) -> Unit indicates a lambda with a String parameter and Unit return type
// lambdas with no parameters may simply be defined using { }
fun executeLambda(f: (s: String) -> Unit) {
val l2 = { fprint("lambdano parameters") }
}
</syntaxhighlight>
 
==="Hello world" example===
Lambdas are declared using braces, {{mono|{ } }}. If a lambda takes parameters, they are declared within the braces and followed by the {{mono|->}} operator.
(Taken from and explained at https://kotlinlang.org/docs/kotlin-tour-hello-world.html.)
<syntaxhighlight lang=kotlin>
 
// the following statement defines a lambda that takes a single parameter and passes it to the println function
<syntaxhighlight lang="kotlin" line="1">
val l = { c -> println(c) }
fun main() {
// lambdas with no parameters may simply be defined using { }
val l2 = { printprintln("noHello, parametersworld!") }
// Hello, world!
}
</syntaxhighlight>
 
==Tools==
* [[IntelliJAndroid IDEAStudio]] (based on IntelliJ IDEA) has plug-inofficial support for Kotlin, starting from Android Studio 3.<ref>{{citeCite web |url = https://pluginsdeveloper.jetbrainsandroid.com/plugin/6954-kotlin |title = Kotlin :: JetBrains Plugin Repositoryand Android|website =Android Plugins.jetbrains.com Developers|access-date =19 June 2017|archive-03-31 |accessdate date=4 2017-04-11 }}</ref> IntelliJ IDEA 15 is the first version to bundle the Kotlin plugin in the IntelliJ Installer, and provide Kotlin support out of the box.<ref>{{cite webOctober 2023|archive-url = https://wwwweb.jetbrainsarchive.comorg/ideaweb/whatsnew20231004062949/ |title = What's New in IntelliJ IDEA 2017https://developer.1 |website = Jetbrainsandroid.com /kotlin|accessdate url-status= 2017-04-11 live}}</ref>
* Integration with common Java build tools is supported, including [[Apache Maven]],<ref>{{cite web |url=https://kotlinlang.org/docs/reference/using-maven.html |title=Using Maven – Kotlin Programming Language |website=kotlinlang.org |access-date=9 May 2017 |archive-date=3 November 2016 |archive-url=https://web.archive.org/web/20161103233907/http://kotlinlang.org/docs/reference/using-maven.html |url-status=live}}</ref> [[Apache Ant]],<ref>{{cite web |url=https://kotlinlang.org/docs/reference/using-ant.html |title=Using Ant – Kotlin Programming Language |website=kotlinlang.org |access-date=9 May 2017 |archive-date=3 November 2016 |archive-url=https://web.archive.org/web/20161103233835/http://kotlinlang.org/docs/reference/using-ant.html |url-status=live}}</ref> and [[Gradle]].<ref>{{cite web |url=https://kotlinlang.org/docs/reference/using-gradle.html |title=Using Gradle – Kotlin Programming Language |website=kotlinlang.org |access-date=9 May 2017 |archive-date=9 November 2016 |archive-url=https://web.archive.org/web/20161109185109/http://kotlinlang.org/docs/reference/using-gradle.html |url-status=live}}</ref>
* JetBrains also provides a plugin for [[Eclipse (software)|Eclipse]].<ref>{{cite web |url = https://kotlinlang.org/docs/tutorials/getting-started-eclipse.html |title = Getting Started with Eclipse Neon - Kotlin Programming Language |website = Kotlinlang.org |date = 2016-11-10 |accessdate = 2017-04-11 }}</ref><ref>{{cite web |url = https://github.com/JetBrains/kotlin-eclipse |title = JetBrains/kotlin-eclipse: Kotlin Plugin for Eclipse |publisher = GitHub |accessdate = 2017-04-11 }}</ref>
* [[Emacs]] has a Kotlin Mode in its MELPA package repository.
* Integration with common Java build tools is supported including [[Apache Maven]],<ref>{{cite web |url = https://kotlinlang.org/docs/reference/using-maven.html |title = Using Maven - Kotlin Programming Language |website = kotlinlang.org |accessdate = 2017-05-09 }}</ref> [[Apache Ant]],<ref>{{cite web |url = https://kotlinlang.org/docs/reference/using-ant.html |title = Using Ant - Kotlin Programming Language |website = kotlinlang.org |accessdate = 2017-05-09 }}</ref> and [[Gradle]].<ref>{{cite web |url = https://kotlinlang.org/docs/reference/using-gradle.html |title = Using Gradle - Kotlin Programming Language |website = kotlinlang.org |accessdate = 2017-05-09 }}</ref>
* JetBrains also provides a plugin for [[Eclipse (software)|Eclipse]].<ref>{{cite web |url=https://kotlinlang.org/docs/tutorials/getting-started-eclipse.html |title=Getting Started with Eclipse Neon – Kotlin Programming Language |website=Kotlinlang.org |date=10 November 2016 |access-date=11 April 2017 |archive-date=18 May 2023 |archive-url=https://web.archive.org/web/20230518022923/https://kotlinlang.org/docs/tutorials/getting-started-eclipse.html |url-status=live}}</ref><ref>{{cite web |url=https://github.com/JetBrains/kotlin-eclipse |title=JetBrains/kotlin-eclipse: Kotlin Plugin for Eclipse |publisher=GitHub |access-date=11 April 2017 |archive-date=16 February 2016 |archive-url=https://web.archive.org/web/20160216150931/https://github.com/JetBrains/kotlin-eclipse |url-status=live}}</ref>
*[[Android Studio]] (based on IntelliJ IDEA) has official support for Kotlin, starting from Android Studio 3. <ref>https://developer.android.com/kotlin/index.html</ref>
* [[IntelliJ IDEA]] has plug-in support for Kotlin.<ref>{{cite web |url=https://plugins.jetbrains.com/plugin/6954-kotlin |title=Kotlin :: JetBrains Plugin Repository |website=Plugins.jetbrains.com |date=31 March 2017 |access-date=11 April 2017 |archive-date=25 June 2023 |archive-url=https://web.archive.org/web/20230625051612/https://plugins.jetbrains.com/plugin/6954-kotlin |url-status=live}}</ref> IntelliJ IDEA 15 was the first version to bundle the Kotlin plugin in the IntelliJ Installer, and to provide Kotlin support out of the box.<ref>{{cite web |url=https://www.jetbrains.com/idea/whatsnew/ |title=What's New in IntelliJ IDEA 2017.1 |website=Jetbrains.com |access-date=11 April 2017 |archive-date=3 October 2023 |archive-url=https://web.archive.org/web/20231003212723/https://www.jetbrains.com/idea/whatsnew/ |url-status=live}}</ref>
*[[Emacs]] has a [https://github.com/Emacs-Kotlin-Mode-Maintainers/kotlin-mode Kotlin Mode] in its Melpa package repository.
* [[Gradle]]: Kotlin has seamless integration with Gradle, a [[build automation]] tool.<ref>{{Cite web |title=Gradle |url=https://kotlinlang.org/docs/gradle.html |access-date=2024-04-08 |website=Kotlin Help |language=en-US |archive-date=8 April 2024 |archive-url=https://web.archive.org/web/20240408064338/https://kotlinlang.org/docs/gradle.html |url-status=live}}</ref>
 
==Kotlin Multiplatform==
{| class="wikitable"
Kotlin Multiplatform allows a single [[codebase]] to target multiple platforms such as [[Microsoft Windows|Windows]], [[Linux]], web, Android and [[iOS]].<ref>{{Cite web |title=Kotlin Multiplatform Overview |url=https://developer.android.com/kotlin/multiplatform |access-date=2025-06-14 |website=Android Developers |language=en}}</ref><ref>{{Cite web |title=Kotlin Multiplatform – Build Cross-Platform Apps |url=https://www.jetbrains.com/kotlin-multiplatform/ |access-date=2025-06-14 |website=JetBrains |language=en}}</ref>
|+ Downloading Kotlin command line binaries
 
! Operating System
Compose Multiplatform is a multi-platform UI framework based on [[Jetpack Compose]]. It is Jetpack Compose for Android ported to Windows, [[macOS]], Linux, web, and iOS.<ref>{{Cite web |title=Compose Multiplatform – Beautiful UIs Everywhere |url=https://www.jetbrains.com/compose-multiplatform/ |access-date=2025-06-14 |website=JetBrains |language=en}}</ref><ref>{{Cite web |title=What's new in Compose Multiplatform 1.8.1 {{!}} Kotlin Multiplatform |url=https://www.jetbrains.com/help/kotlin-multiplatform-dev/whats-new-compose-180.html |access-date=2025-06-14 |website=Kotlin Multiplatform Help |language=en-US}}</ref><ref>{{Cite web |title=Compatibility and versions {{!}} Kotlin Multiplatform |url=https://www.jetbrains.com/help/kotlin-multiplatform-dev/compose-compatibility-and-versioning.html |access-date=2025-06-14 |website=Kotlin Multiplatform Help |language=en-US}}</ref> Jetpack Compose uses a Kotlin compiler plugin to transform composable functions into UI elements.<ref>{{Citation |last=Panjuta |first=Denis |title=Basic Jetpack Compose Elements |date=2023-12-12 |work=Tiny Android Projects Using Kotlin |pages=233–257 |url=https://doi.org/10.1201/9781032622538-9 |access-date=2025-06-14 |place=Boca Raton |publisher=Chapman and Hall/CRC |isbn=978-1-032-62253-8 |last2=Nwokike |first2=Loveth}}</ref> For example, the Text composable function displays a text label on the screen.
! Package Manager
! Command
|-
| [[Windows]]
| [[GitHub]]
| download zip from https://github.com/JetBrains/kotlin/releases/tag/v1.2.30 (also, requires Java 8 JDK)
|-
| [[Windows]]
| [[Android Studio]]
| Add to path C:\Program Files\Android\Android Studio\plugins\Kotlin\kotlinc\bin and C:\Program Files\Android\Android Studio\jre\bin
|-
| [[Cygwin | Windows / Cygwin]]
| sdkman.io
| $ curl -s https://get.sdkman.io &#124; bash; $ sdk install kotlin
|-
| [[macOS]]
| [[Homebrew (package management software) | Homebrew]]
| $ brew update; $ brew install kotlin
|-
| [[macOS]]
| [[MacPorts]]
| $ sudo port install kotlin
|-
| [[Ubuntu (operating system) | Ubuntu Linux]]
| [[Snappy (package manager) | Snappy]]
| $ sudo snap install --classic kotlin
|-
| [[Linux | Linux Generic]]
| sdkman.io
| $ curl -s https://get.sdkman.io &#124; bash; $ sdk install kotlin
|}
 
==Applications==
When Kotlin was announced as an official Android development language at [[Google I/O]] in May 2017, it became the third language fully supported for Android, after Java and C++.<ref>{{Cite news |last1=Lardinois|first1=Frederic |url=https://techcrunch.com/2017/05/17/google-makes-kotlin-a-first-class-language-for-writing-android-apps/ |title=Google makes Kotlin a first-class language for writing Android apps |website=techcrunch.com |language=en-US |date=17 May 2017 |access-date=28 June 2018 |url-status=live |archive-url=https://web.archive.org/web/20170522065631/https://techcrunch.com/2017/05/17/google-makes-kotlin-a-first-class-language-for-writing-android-apps/ |archive-date=22 May 2017}}</ref> {{As of|2020}}, Kotlin was the most widely used language on Android, with Google estimating that 70% of the top 1,000 apps on the Play Store were written in Kotlin. Google itself had 60 apps written in Kotlin, including Maps and Drive. Many Android apps, such as Google Home, were in the process of being migrated to Kotlin, and therefore use both Kotlin and Java. Kotlin on Android is seen as beneficial for its [[null-pointer safety]], as well as for its features that make for shorter, more readable code.<ref>{{cite web|url=https://www.zdnet.com/article/google-were-using-kotlin-programming-language-to-squash-the-bugs-that-cause-most-crashes/|website=ZDNet|title=Kotlin programming language: How Google is using it to squash the code bugs that cause most crashes|access-date=6 December 2020|archive-date=6 April 2023|archive-url=https://web.archive.org/web/20230406045458/https://www.zdnet.com/article/google-were-using-kotlin-programming-language-to-squash-the-bugs-that-cause-most-crashes/|url-status=live}}</ref>
One of the obvious applications of Kotlin is [[Android (operating system)|Android]] development. The platform was stuck on Java 7 for a while (with some contemporary language features made accessible through the use of Retrolambda<ref>{{cite web |url = https://github.com/orfjackal/retrolambda |title = orfjackal/retrolambda: Backport of Java 8's lambda expressions to Java 7, 6 and 5 |publisher = GitHub |access-date = 2017-05-09 }}</ref> or the Jack toolchain<ref>{{cite web|url=https://source.android.com/source/jack.html|title=Jack (Java Android Compiler Kit) {{!}} Android Open Source Project|website=source.android.com|access-date=2016-04-15}}</ref>) and Kotlin introduces many improvements for programmers such as null-pointer safety, extension functions and infix notation. Accompanied by full Java compatibility and good IDE support (''Android Studio''<ref>{{cite web |url = https://plugins.jetbrains.com/plugin/6954 |title = JetBrains Plugin Repository :: Kotlin |website = plugins.jetbrains.com |access-date = 2016-04-15 }}</ref>) it is intended to improve code readability, give an easier way to extend Android SDK classes and speed up development.<ref>{{cite web |url = https://themindstudios.com/blog/kotlin-vs-java-will-kotlin-replace-java/ |title = Will Kotlin Replace Java? |website = themindstudios.com |accessdate = 2017-03-10 }}</ref>
 
Ktor is Jetbrains Kotlin first framework for building server and client applications.<ref>{{Citation |title=ktorio/ktor |date=2025-06-16 |url=https://github.com/ktorio/ktor |access-date=2025-06-16 |publisher=ktor.io}}</ref><ref>{{Cite web |title=Welcome {{!}} Ktor |url=https://ktor.io/docs/3.1.3/welcome.html |access-date=2025-06-16 |website=Ktor Help |language=en-US}}</ref> The [[Spring Framework]] officially added Kotlin support with version 5, on 4 January 2017.<ref>{{cite web |url=https://spring.io/blog/2017/01/04/introducing-kotlin-support-in-spring-framework-5-0 |website=Spring |title=Introducing Kotlin support in Spring Framework 5.0 |date=4 January 2017 |publisher=Pivotal |access-date=29 September 2020 |archive-date=23 August 2023 |archive-url=https://web.archive.org/web/20230823031409/https://spring.io/blog/2017/01/04/introducing-kotlin-support-in-spring-framework-5-0/ |url-status=live}}</ref> To further support Kotlin, Spring has translated all its documentation to Kotlin, and added built-in support for many Kotlin-specific features such as [[coroutines]].<ref>{{cite web|title=The State of Kotlin Support in Spring|url=https://blog.jetbrains.com/kotlin/2020/08/the-state-of-kotlin-support-in-spring/|website=JetBrains|date=14 August 2020|access-date=6 December 2020|language=en|archive-date=7 June 2023|archive-url=https://web.archive.org/web/20230607090327/https://blog.jetbrains.com/kotlin/2020/08/the-state-of-kotlin-support-in-spring/|url-status=live}}</ref>
Kotlin was announced as an official Android development language at [[Google I/O]] 2017. It became the third language fully supported for Android, in addition to Java and C++.<ref>{{cite web |url = https://www.eyerys.com/articles/news/kotlin-officially-joining-androids-family-addition-java-and-c |title = Kotlin Is Officially Joining The Android's Family, In Addition To Java And C++ |website = Eyerys |date = May 18, 2017 |accessdate = May 18, 2017 }}</ref>
 
In 2020, JetBrains found in a survey of developers who use Kotlin that 56% were using Kotlin for mobile apps, while 47% were using it for a web back-end. Just over a third of all Kotlin developers said that they were migrating to Kotlin from another language. Most Kotlin users were targeting Android (or otherwise on the JVM), with only 6% using Kotlin Native.<ref>{{cite web |title=Kotlin Programming - The State of Developer Ecosystem 2020 |url=https://www.jetbrains.com/lp/devecosystem-2020/kotlin/ |website=JetBrains |access-date=29 September 2020 |language=en |archive-date=5 April 2023 |archive-url=https://web.archive.org/web/20230405081654/https://www.jetbrains.com/lp/devecosystem-2020/kotlin/ |url-status=live}}</ref>
 
==Adoption==
In 2018, Kotlin was the fastest growing language on GitHub, with 2.6 times more developers compared to 2017.<ref>{{cite web |url=https://octoverse.github.com/projects |title=The state of the Octoverse |access-date=24 July 2019 |archive-url=https://web.archive.org/web/20190322190823/https://octoverse.github.com/projects |archive-date=22 March 2019 |url-status=dead}}</ref> It is the fourth most loved programming language according to the 2020 Stack Overflow Developer Survey.<ref>{{cite web|title=Stack Overflow Developer Survey 2020|url=https://insights.stackoverflow.com/survey/2020#most-loved-dreaded-and-wanted|access-date=28 May 2020|archive-date=4 June 2020|archive-url=https://web.archive.org/web/20200604090141/https://insights.stackoverflow.com/survey/2020#most-loved-dreaded-and-wanted|url-status=live}}</ref>
According to the Kotlin website, [[Prezi]] is using Kotlin in the backend.<ref>{{cite web |url = https://kotlinlang.org/ |title = Kotlin Programming Language |website = Kotlinlang.org |accessdate = 2017-04-11 }}</ref> DripStat has done a writeup of their experience with Kotlin.<ref>{{cite web |url = https://blog.dripstat.com/kotlin-in-production-the-good-the-bad-and-the-ugly-2/ |title = Kotlin in Production - What works, Whats broken |website = Blog.dripstat.com |date = 2016-09-24 |accessdate = 2017-04-11 }}</ref>
 
Kotlin was also awarded the O'Reilly Open Source Software Conference Breakout Award for 2019.<ref>{{cite web|url=https://blog.jetbrains.com/kotlin/2019/07/kotlin-wins-breakout-project-of-the-year-award-at-oscon-19/|title=Kotlin wins Breakout Project of the Year award at OSCON '19|date=18 July 2019|access-date=24 July 2019|archive-date=17 May 2022|archive-url=https://web.archive.org/web/20220517113227/https://blog.jetbrains.com/kotlin/2019/07/kotlin-wins-breakout-project-of-the-year-award-at-oscon-19/|url-status=live}}</ref>
 
Many companies/organizations have used Kotlin for backend development:
* [[Allegro (website)|Allegro]]<ref>{{cite web |title=Kotlin at Allegro |url=https://talkingkotlin.com/kotlin-at-allegro/ |website=Talking Kotlin |date=October 2018 |access-date=29 September 2020 |language=en |archive-date=1 June 2023 |archive-url=https://web.archive.org/web/20230601132552/https://talkingkotlin.com/kotlin-at-allegro/ |url-status=live}}</ref>
* Amazon<ref>{{cite web |title=QLDB at Amazon |url=https://talkingkotlin.com/qldb/ |website=Talking Kotlin |date=30 June 2020 |access-date=29 September 2020 |archive-date=1 June 2023 |archive-url=https://web.archive.org/web/20230601121344/https://talkingkotlin.com/qldb/ |url-status=live}}</ref>
* Atlassian<ref>{{cite web |title=Future of Jira Software powered by Kotlin |url=https://www.youtube.com/watch?v=4GkoB4hZUnw |website=YouTube | date=29 October 2019 |access-date=1 September 2023 |archive-date=1 September 2023 |archive-url=https://web.archive.org/web/20230901061928/https://www.youtube.com/watch?v=4GkoB4hZUnw |url-status=live}}</ref>
* Cash App<ref>{{cite web |title=Going Full Kotlin Multiplatform |url=https://talkingkotlin.com/going-full-kotlin-multiplatform/ |website=Talking Kotlin |date=14 April 2020 |access-date=29 September 2020 |language=en |archive-date=5 April 2023 |archive-url=https://web.archive.org/web/20230405221631/https://talkingkotlin.com/going-full-kotlin-multiplatform/ |url-status=live}}</ref><ref>{{cite web |url=https://github.com/square/sqldelight |title=square/sqldelight |website=[[GitHub]] |access-date=24 July 2019 |archive-date=20 June 2019 |archive-url=https://web.archive.org/web/20190620112740/https://github.com/square/sqldelight |url-status=live}}</ref>
* Flux<ref>{{cite web |title=Using Kotlin for backend development at Flux |url=https://talkingkotlin.com/Using-Kotlin-for-backend-development-at-Flux/ |website=Talking Kotlin |date=14 August 2019 |access-date=29 September 2020 |language=en |archive-date=1 June 2023 |archive-url=https://web.archive.org/web/20230601111601/https://talkingkotlin.com/Using-Kotlin-for-backend-development-at-Flux/ |url-status=live}}</ref>
* Google<ref>{{cite web |title=State of Kotlin on Android |url=https://www.youtube.com/watch?v=AgPj1Q6D--c&feature=youtu.be&t=309 |access-date=29 September 2020 |website=YouTube | date=10 June 2020 |archive-date=15 January 2023 |archive-url=https://web.archive.org/web/20230115223201/https://www.youtube.com/watch?v=AgPj1Q6D--c&feature=youtu.be&t=309 |url-status=live}}</ref>
* Gradle<ref>{{cite web |title=Gradle Kotlin DSL Primer |url=https://docs.gradle.org/current/userguide/kotlin_dsl.html |website=docs.gradle.org |access-date=29 September 2020 |archive-date=18 August 2023 |archive-url=https://web.archive.org/web/20230818005932/https://docs.gradle.org/current/userguide/kotlin_dsl.html |url-status=live}}</ref>
* JetBrains<ref>{{cite web |title=Kotless |url=https://talkingkotlin.com/kotless/ |website=Talking Kotlin |date=30 January 2020 |access-date=29 September 2020 |language=en |archive-date=5 April 2023 |archive-url=https://web.archive.org/web/20230405081655/https://talkingkotlin.com/kotless/ |url-status=live}}</ref>
* Meshcloud<ref>{{cite web |title=Kotlin on the backend at Meshcloud |url=https://talkingkotlin.com/kotlin-on-the-backend-at-meshcloud/ |website=Talking Kotlin |date=28 February 2018 |access-date=29 September 2020 |language=en |archive-date=6 April 2023 |archive-url=https://web.archive.org/web/20230406111418/https://talkingkotlin.com/kotlin-on-the-backend-at-meshcloud/ |url-status=live}}</ref>
* Norwegian Tax Administration<ref>{{cite web |title=KotlinConf 2019: Kotlin Runs Taxes in Norway by Jarle Hansen & Anders Mikkelsen |url=https://www.youtube.com/watch?v=K8XxaAba65g&list=PLQ176FUIyIUY6SKGl3Cj9yeYibBuRr3Hl&index=22 |website=YouTube | date=16 December 2019 |access-date=29 September 2020 |archive-date=10 April 2023 |archive-url=https://web.archive.org/web/20230410210206/https://www.youtube.com/watch?v=K8XxaAba65g&list=PLQ176FUIyIUY6SKGl3Cj9yeYibBuRr3Hl&index=22 |url-status=live}}</ref>
* OLX<ref>{{cite web |title=Greenfield Kotlin at OLX |url=https://talkingkotlin.com/greenfield-kotlin-at-olx/ |website=Talking Kotlin |date=24 August 2018 |access-date=29 September 2020 |language=en |archive-date=1 June 2023 |archive-url=https://web.archive.org/web/20230601115345/https://talkingkotlin.com/greenfield-kotlin-at-olx/ |url-status=live}}</ref>
* Pivotal<ref>{{cite web |title=Application Monitoring with Micrometer |url=https://talkingkotlin.com/application-monitoring-with-micrometer/ |website=Talking Kotlin |date=14 June 2018 |access-date=29 September 2020 |language=en |archive-date=1 April 2023 |archive-url=https://web.archive.org/web/20230401140822/https://talkingkotlin.com/application-monitoring-with-micrometer/ |url-status=live}}</ref>
* Rocket Travel<ref>{{cite web |title=Groovy and Kotlin Interop at Rocket Travel |url=https://talkingkotlin.com/groovy-and-kotlin-interop-at-rocket-travel/ |website=Talking Kotlin |date=14 May 2018 |access-date=29 September 2020 |language=en |archive-date=5 April 2023 |archive-url=https://web.archive.org/web/20230405081653/https://talkingkotlin.com/groovy-and-kotlin-interop-at-rocket-travel/ |url-status=live}}</ref>
* Shazam<ref>{{cite web |title=Kotlin at Shazam |url=https://talkingkotlin.com/kotlin-at-shazam/ |website=Talking Kotlin |date=29 July 2018 |access-date=29 September 2020 |language=en |archive-date=1 April 2023 |archive-url=https://web.archive.org/web/20230401145508/https://talkingkotlin.com/kotlin-at-shazam/ |url-status=live}}</ref>
* Zalando<ref>{{cite web |title=Zally - An API Linter |url=https://talkingkotlin.com/Zally-An-API-Linter/ |website=Talking Kotlin |date=29 January 2018 |access-date=29 September 2020 |language=en |archive-date=6 April 2023 |archive-url=https://web.archive.org/web/20230406111421/https://talkingkotlin.com/Zally-An-API-Linter/ |url-status=live}}</ref>
 
Some companies/organizations have used Kotlin for web development:
 
* Barclay's Bank<ref>{{cite web |title=Java/Kotlin Developer - Barclays - Prague - Wizbii |url=https://www.wizbii.com/company/barclays/job/convertibles-trading-system-developer |website=Wizbii.com |access-date=29 September 2020 |language=en}}</ref>
* Data2viz<ref>{{cite web |title=KotlinConf 2017 - Frontend Kotlin from the Trenches by Gaetan Zoritchak |url=https://www.youtube.com/watch?v=1Pu0TYJJ2Tw&list=PLQ176FUIyIUY6UK1cgVsbdPYA3X5WLam5&index=14 |website=YouTube | date=30 November 2017 |access-date=29 September 2020 |archive-date=10 April 2023 |archive-url=https://web.archive.org/web/20230410010605/https://www.youtube.com/watch?v=1Pu0TYJJ2Tw&list=PLQ176FUIyIUY6UK1cgVsbdPYA3X5WLam5&index=14 |url-status=live}}</ref>
* Fritz2<ref>{{cite web |title=Fritz2 |url=https://talkingkotlin.com/fritz2/ |website=Talking Kotlin |date=14 September 2020 |access-date=29 September 2020 |language=en |archive-date=6 April 2023 |archive-url=https://web.archive.org/web/20230406204445/https://talkingkotlin.com/fritz2/ |url-status=live}}</ref>
* JetBrains<ref>{{cite web |title=KotlinConf 2019: Kotlin in Space by Maxim Mazin |url=https://www.youtube.com/watch?v=JnmHqKLgYY4 |website=YouTube | date=18 December 2019 |access-date=29 September 2020 |archive-date=9 April 2023 |archive-url=https://web.archive.org/web/20230409112530/https://www.youtube.com/watch?v=JnmHqKLgYY4 |url-status=live}}</ref>
 
A number of companies have publicly stated they were using Kotlin:
According to Jetbrains blog, Kotlin is used by Amazon Web Services, Pinterest, Coursera, Netflix, Uber, Square, Trello, [[Basecamp (software)|Basecamp]],<ref>{{Cite news |url = https://m.signalvnoise.com/how-we-made-basecamp-3s-android-app-100-kotlin-35e4e1c0ef12 |title = How we made Basecamp 3’s Android app 100% Kotlin – Signal v. Noise |date = 2017-04-29 |work = Signal v. Noise |access-date = 2017-05-01 }}</ref> and others. Corda, a distributed ledger developed by a consortium of well-known banks (such as Goldman Sachs, Wells Fargo, J.P. Morgan, Deutsche Bank, UBS, HSBC, BNP Paribas, Société Générale), has over 90% Kotlin in its codebase.
<ref>{{Cite news |url = https://blog.jetbrains.com/kotlin/2017/03/kotlin-1-1/ |title = Kotlin 1.1 Released with JavaScript Support, Coroutines and more |access-date = 2017-05-01 }}</ref>
 
* [[Basecamp (software)|Basecamp]]<ref>{{Cite news |url=https://m.signalvnoise.com/how-we-made-basecamp-3s-android-app-100-kotlin-35e4e1c0ef12 |archive-url=https://wayback.archive-it.org/all/20180801160548/https://m.signalvnoise.com/how-we-made-basecamp-3s-android-app-100-kotlin-35e4e1c0ef12?gi=e9a4b3c9bf9f |url-status=dead |archive-date=1 August 2018 |title=How we made Basecamp 3's Android app 100% Kotlin – Signal v. Noise |date=29 April 2017 |work=Signal v. Noise |access-date=1 May 2017}}</ref>
According to Google, Kotlin has already been adopted by several major developers — [[Expedia]], Flipboard, [[Pinterest]], Square, and others — for their Android production apps.<ref>{{Cite news |url = https://android-developers.googleblog.com/2017/05/android-announces-support-for-kotlin.html |title = Android Announces Support for Kotlin |date = 2017-05-17 |access-date = 2017-05-19 }}</ref>
* Corda, a distributed ledger developed by a consortium of well-known banks (such as [[Goldman Sachs]], [[Wells Fargo]], [[JPMorgan Chase|J.P. Morgan]], [[Deutsche Bank]], [[UBS]], [[HSBC]], [[BNP Paribas]], and [[Société Générale]]), has over 90% Kotlin code in its codebase.{{Citation needed|date=July 2025|reason=Making a big claim and naming a lot of names here, so where's the source?}}
* [[Coursera]]<ref>{{cite web |url=https://medium.com/coursera-engineering/becoming-bilingual-coursera-d8048dce73e3 |title=Becoming bilingual@coursera |date=26 April 2018 |access-date=24 July 2019 |archive-date=15 January 2023 |archive-url=https://web.archive.org/web/20230115223242/https://medium.com/coursera-engineering/becoming-bilingual-coursera-d8048dce73e3 |url-status=live}}</ref>
* DripStat<ref>{{cite web |url=https://blog.dripstat.com/kotlin-in-production-the-good-the-bad-and-the-ugly-2/ |title=Kotlin in Production – What works, Whats broken |website=Blog.dripstat.com |date=24 September 2016 |access-date=11 April 2017 |archive-date=1 July 2019 |archive-url=https://web.archive.org/web/20190701030659/https://blog.dripstat.com/kotlin-in-production-the-good-the-bad-and-the-ugly-2/ |url-status=dead}}</ref>
* [[Duolingo]]<ref>{{cite web |last1=Chaidarun |first1=Art |title=Migrating Duolingo's Android app to 100% Kotlin |url=https://blog.duolingo.com/migrating-duolingos-android-app-to-100-kotlin/ |website=Duolingo Blog |language=en |date=6 April 2020}}</ref>
* [[Meta Platforms|Meta]]<ref>{{cite web |url=https://www.infoq.com/news/2022/11/meta-port-java-kotlin/ |title=Porting Million Lines of Code from Java to Kotlin at Meta }}</ref>
* [[Netflix]]<ref>{{cite web |url=https://twitter.com/robspieldenner/status/708355228832178176 |title=Rob Spieldenner on twitter |access-date=24 July 2019 |archive-date=25 December 2022 |archive-url=https://web.archive.org/web/20221225132754/https://twitter.com/robspieldenner/status/708355228832178176 |url-status=live}}</ref>
* [[Pinterest]]<ref>{{cite web |url=https://www.youtube.com/watch?v=mDpnc45WwlI |title=Droidcon NYC 2016 - Kotlin in Production |website=[[YouTube]] |date=3 November 2016 |access-date=24 July 2019 |archive-date=14 April 2023 |archive-url=https://web.archive.org/web/20230414150938/https://www.youtube.com/watch?v=mDpnc45WwlI |url-status=live}}</ref>
* [[Trello]]<ref>{{cite web |url=https://twitter.com/danlew42/status/809065097339564032 |title=Dan Lew on Twitter |access-date=24 July 2019 |archive-date=2 May 2023 |archive-url=https://web.archive.org/web/20230502024553/https://twitter.com/danlew42/status/809065097339564032 |url-status=live}}</ref>
* [[Uber]]<ref>{{cite web |date=30 April 2019 |title=Measuring Kotlin Build Performance at Uber |url=https://www.uber.com/blog/measuring-kotlin-build-performance/ |access-date=6 March 2024 |archive-date=5 June 2023 |archive-url=https://web.archive.org/web/20230605173159/https://www.uber.com/blog/measuring-kotlin-build-performance/ |url-status=live}}</ref>
 
== See also ==
{{Portal|Free and open-source software|Computer programming}}
* [[Comparison of programming languages]]
* [https://discuss.kotlinlang.org/ Kotlin Forum]
 
==References==
* This article contains quotations from [http://kotlinlang.org/docs/tutorials/command-line.html Kotlin tutorials] which are released under a [https://www.apache.org/licenses/LICENSE-2.0an Apache 2.0 license].
{{Reflist}}
 
==External links==
* {{Official website}}
* [https://try.kotlinlang.org Web-Demo and examples]
 
{{Java (software platform)}}
{{Programming languages}}
 
[[Category:Java2011 platformsoftware]]
[[Category:Free software projects]]
[[Category:High-level programming languages]]
[[Category:Java programming language family]]
[[Category:JVM programming languages]]
Line 443 ⟶ 490:
[[Category:Software using the Apache license]]
[[Category:Statically typed programming languages]]
[[Category:High-level programming languages]]
[[Category:2011 software]]
[[Category:Free software projects]]