This tutorial assumes that all you know is Java, but you want to learn Kotlin.
Please note that the resources are in the wiki page.
A few things that are worth watching to know more about Kotlin.
By me: Odd things to look out for when converting code to Kotlin
By me: Code clean-up with Kotlin
By me (newer article!): An opinionated guide on how to make your Kotlin code fun to read and joy to work with
Android KTX source code: Github snapshot or AOSP (actively developed)
inverted argument order, no semi-colons, void vs Unit, Object vs Any?, fun-Major-Syntax-Differences#inverted-argument-order-no-semi-colons-void-vs-unit-object-vs-any-fun)
interfaces with val, var and fun-Major-Syntax-Differences#interfaces-with-val-var-and-fun)
constructors, inheritance-Major-Syntax-Differences#constructors-inheritance)
lateinit vars-Major-Syntax-Differences#lateinit-vars)
enum class-Major-Syntax-Differences#enum-class)
annotation class-Major-Syntax-Differences#annotation-class)
final by default vs open-Major-Syntax-Differences#final-by-default-vs-open)
for loops (in ranges, until)-Major-Syntax-Differences#for-loops-in-ranges-until)
object for singleton-Major-Syntax-Differences#object-for-singleton)
statics via companion object, const val-Major-Syntax-Differences#statics-via-companion-object-const-val)
visibility in Kotlin (public by default, private, protected, internal)-Major-Syntax-Differences#visibility-in-kotlin-public-by-default-private-protected-internal)
static nested class in Java vs inner class in Kotlin-Major-Syntax-Differences#static-nested-class-in-java-vs-inner-class-in-kotlin)
backticks for reserved keywords (Mockito.when, $) and import aliases-Major-Syntax-Differences#backticks-for-reserved-keywords-mockitowhen--and-import-aliases)
is instead of instanceof, as and as? for casting-Major-Syntax-Differences#is-instead-of-instanceof-as-and-as-for-casting)
creating anonymous implementations for classes/interfaces-Major-Syntax-Differences#creating-anonymous-implementations-for-classesinterfaces)
there is no condition ? true : false ternary operator-Major-Syntax-Differences#there-is-no-condition--true--false-ternary-operator)
arrayOf and arrayOfNulls and listOf and mutableListOf and linkedMapOf-Major-Syntax-Differences#arrayof-and-arrayofnulls-and-listof-and-mutablelistof-and-linkedmapof)
array literals in annotations (for vararg parameters)-Major-Syntax-Differences#array-literal-in-annotations-even-for-single-argument-vararg-parameter)
operator conventions (get() vs [], .equals() vs ==)-Major-Syntax-Differences#operator-conventions-get-vs--equals-vs-)
there are no checked exceptions, try-with-resources as .use {}-Major-Syntax-Differences#there-are-no-checked-exceptions-use)
@Volatile and synchronized-Major-Syntax-Differences#volatile-is-replaced-with-volatile)
multiple generic bounds-Major-Syntax-Differences#multiple-generic-bounds)
typed nullability, and null-safety operators (?., ?:)-Basic-Kotlin-Features#typed-nullability-and-null-safety-operators--)
smart casting (and mutable vars gotcha)-Basic-Kotlin-Features#smart-casting-and-mutable-vars-gotcha)
lateinit vars-Basic-Kotlin-Features#lateinit-vars)
properties, backing fields-Basic-Kotlin-Features#properties-backing-fields)
string interpolation and """multiline escaped ${strings}"""-Basic-Kotlin-Features#string-interpolation-and-multiline-escaped-strings)
data classes-Basic-Kotlin-Features#data-classes)
when
keyword (and complex conditions, such as ranges)-Basic-Kotlin-Features#when-keyword)
control statement as expression (assignment of when
, return
, ...)-Basic-Kotlin-Features#control-statement-as-expression-assignment-of-when-return)
named arguments, default arguments-Basic-Kotlin-Features#named-arguments-default-arguments)
vararg and the * spread operator-Basic-Kotlin-Features#vararg-and-the--spread-operator)
interfaces and default implementation-Basic-Kotlin-Features#interfaces-and-default-implementation)
generics (<T: Blah>
, in/out
, and star projection <*>
)-Basic-Kotlin-Features#generics-t-blah-inout-and-star-projection-)
lambda types, trailing lambdas-The-Cool-Stuff#lambda-types-trailing-lambdas)
method reference-The-Cool-Stuff#method-reference)
typealias
-The-Cool-Stuff#typealias)
lambdas with receivers-The-Cool-Stuff#lambdas-with-receivers)
extension functions, extension properties-The-Cool-Stuff#extension-functions-extension-properties)
standard library functions - scoping functions: apply
, let
, also
, run
, with
-The-Cool-Stuff#standard-library-functions---scoping-functions-apply-let-also-run-with)
standard library functions - more utility functions: takeIf
, takeUnless
-The-Cool-Stuff#standard-library-functions---more-utility-functions-takeif-takeunless)
tailrec
keyword-The-Cool-Stuff#tailrec-keyword)
inline
functions (crossinline
, noinline
)-The-Cool-Stuff#inline-functions-crossinline-noinline)
*a glance at the Collections API-The-Cool-Stuff#a-glance-at-the-collections-api) (see API here)
inline fun <reified T>
-The-Cool-Stuff#inline-fun-reified-t)
sealed
classes-The-Cool-Stuff#sealed-classes)
infix
keyword-The-Cool-Stuff#infix-keyword)
tuples (to
) and destructuring-The-Cool-Stuff#infix-keyword)
*extension operators (componentN
)-The-Tricky-Stuff#extension-operators-componentn)
*property delegates (and built-in ones: lazy
, observable
/vetoable
, by map
for configurations via Map<String, Any?>
)-The-Tricky-Stuff#property-delegates-and-built-in-ones-lazy-observablevetoable-by-map-for-configurations-via-mapstring-any)
delegation by class-The-Tricky-Stuff#delegation-by-class)
*JVM annotations: @JvmOverloads
, @JvmField
, @JvmSuppressWildcards
, @get:
and @set:
and @field:
-The-Tricky-Stuff#jvm-annotations-jvmoverloads-jvmfield-jvmstatic-jvmsuppresswildcards-get-and-set-and-field)
synthetic view accessors with kotlin android extensions (deprecated)-Android-Specific-Stuff#synthetic-view-accessors-with-kotlin-android-extensions)
@Parcelize data class
with experimental kotlin android extensions-Android-Specific-Stuff#parcelize-data-class-with-experimental-kotlin-android-extensions)
Coroutines, coroutines on Android, suspend fun
Channels: LinkedListChannel, BroadcastChannel
@DslMarker
multi-platform things: expect
and actual
contracts
Copyright 2018-2020 Gabor Varadi
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.