User Tools

Site Tools


kotlin_topics

Table of Contents

Kotlin Topics

Return to Kotlin, Programming topics or Topics

See Syntax highlighting - https://www.dokuwiki.org/syntax_highlighting

Snippet from Wikipedia: Kotlin (programming language)

Kotlin () is a cross-platform, statically typed, general-purpose high-level programming language with type inference. Kotlin is designed to interoperate fully with Java, and the JVM version of Kotlin's standard library depends on the Java Class Library, but type inference allows its syntax to be more concise. Kotlin mainly targets the JVM, but also compiles to JavaScript (e.g., for frontend web applications using React) or native code via LLVM (e.g., for native iOS apps sharing business logic with Android apps). Language development costs are borne by JetBrains, while the Kotlin Foundation protects the Kotlin trademark.

On 7 May 2019, Google announced that the Kotlin programming language was now its preferred language for Android app developers. 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 produces Java 8 bytecode by default (which runs in any later JVM), but lets the programmer choose to target Java 9 up to 20, for optimization, or allows for more features; has bidirectional record class interoperability support for JVM, introduced in Java 16, considered stable as of Kotlin 1.5.

Kotlin has support for the web with Kotlin/JS, either through a classic interpreter-based backend which has been declared stable since version 1.3, or an intermediate representation-based backend which has been declared stable since version 1.8. Kotlin/Native (for e.g. Apple silicon support) is considered beta since version 1.3.

Table of Contents

while, do/while 3.1.3

when (like switch) 3.1.4

try/catch/finally 3.1.5

Classes and Objects 4.1

Constructors and members 4.1.1

Imports and packages 4.1.2

Class members 4.1.3

Getters and setters 4.1.4

Constructor default values 4.1.5

Secondary constructors 4.1.6

Open and final classes 4.1.7

Abstract classes 4.1.8

Interfaces 4.1.9

== and === 4.1.10

Enumerations 4.1.11

A complete class 4.1.12

Data classes 4.1.13

Objects 4.1.14

Companion objects 4.1.15

Visibility modifiers 4.1.16

Functions 5.1

Extension functions 5.1.1

Infix functions 5.1.2

Anonymous functions 5.1.3

Passing functions around 5.1.4

vararg parameters 5.1.5

Nullability 6.1

Nullable types 6.1.1

Safe-call operator 6.1.2

Elvis operator 6.1.3

let operator 6.1.4

!! operator 6.1.5

Nullability example 6.1.6

Nullability summary 6.1.7

Collections 7.1

Array 7.1.1

List 7.1.2

Map 7.1.3

Set 7.1.4

Sequence methods 7.1.5

Map methods 7.1.6

Miscellaneous 8.1

A Swing example 8.1.1

Build tools 8.1.2

Idioms 8.1.3

An OOP example 8.1.4

An FP example 8.1.5

Command line 8.1.6

Android 9.1

Contributors 10.1

License 10.2

About 10.3

Kotlin Quick Reference

Introduction

Kotlin Quick Reference is intended to provide a quick reference to the Kotlin programming language. Each chapter in the book demonstrates Kotlin syntax and provides examples to explain the chapter’s topic. This is done in a brisk manner, with as few words as necessary.

Audience

Because this book provides only a quick reference to the Kotlin language, it’s intended for developers who have experience in other programming languages and just need a fast reference to Kotlin features. If you need a more complete book, Kotlin in Action is an excellent resource.

Preface

Release information

This is Release 0.1 of Kotlin Quick Reference.

Loving Scala … and Kotlin

Since 2011 I’ve been using the Scala programming language. I fell in love with as soon as I saw it, so much so that I wrote three books about it:

Scala Cookbook

Functional Programming, Simplified

Hello, Scala

The only problem I have with Scala is that I enjoy developing Android applications, and with the exception of the Scala on Android project — which hasn’t had a new release since February 24, 2017 — there isn’t a simple way to create Android applications with Scala. So when I looked into Kotlin and saw that it was very similar to Scala, well, I was pretty happy.

What I love about Kotlin

What I love about both Kotlin (and Scala) can be summed up this way:

The syntax is as elegant and concise as Ruby

Everything feels dynamic, but it’s statically typed

Source code compiles to class files that run on the JVM

You can use all of the thousands of Java libraries in existence

Just as I’ve seen with Scala, the Kotlin creators state that as a rough estimate, Kotlin requires about 40% fewer lines of code than Java

Developing Android applications with Kotlin is just as easy (easier!) as creating Android applications with Java

Goal of this book

While there are now many good Kotlin books available, and the documentation on the Kotlin website is excellent, I’ve found that what I want is a quick reference to the Kotlin language. Having used multiple programming languages before — including Scala — I don’t need a lot of discussion about a new language, I mostly just need to see the language’s syntax and some good examples.

Therefore, my goal in this book is to provide a quick reference to the Kotlin language — light on words, and heavy on demonstrating syntax and examples.

S

Kotlin singleton - “A Kotlin object declared with the Kotlin object keyword; singletons are limited to a single instance throughout program execution.” B07FXQ7SQN

Fair Use Source: http://kotlin-quick-reference.com

kotlin_topics.txt · Last modified: 2020/11/20 01:10 by 127.0.0.1