# -include-runtime to work with lists for instance
$ kotlinc -verbose -include-runtime -d hello.jar *.kt
$ java -jar hello.jar
- Class members (methods and properties) are public by default.
- Use
private
to make them visible inside the class only.
Programming paradigm concerned with async data streams and the automatic propagation of change (e.g. Flow in Kotlin).
- Wikipedia definition: Functions that pause and resume execution without blocking.
- In Kotlin: runs concurrently with the rest of the code (similar to a thread, but more lightweight).
- A function that can be paused and resumed, and that runs inside a coroutine.
- It can be called within a coroutine scope or from another suspend function.
- Run a coroutine concurrently (without blocking the current thread).
- Runs in a coroutine scope. I.e. inside
runBlocking()
block for non-Android apps, or in ViewModelScope
or lifecycleScope
(for Activity) in Android apps.
- Used to define a class & create an instance of it (i.e. singleton) in a single step.
- Cannot have a constructor (primary or secondary).
Used to implement a POJO (Plain old Java object) but with auto-generated methods (e.g. to print object in readable format, to compare instances...).
- Similaly to data classes, has a few auto-generated methods (toString(), equals()).
- But has a single instance at runtime.
- Has a fixed number of subclasses known at compile time.
- Subclasses must be declared in the same package as the sealed class.
- Used to hold state (e.g. UI state).
- In contrast with
enum
, each state (i.e. subclass) can hold non-const data.
data class
commonly used for states holding data, and data object
(i.e. singleton) for those that don't.
- They support polymorphism, just like interfaces and abstract classes.
- The value of an instance of type
Lazy
is calculated on the first access.
- Subsequent calls only return remembered results.
- e.g. The value returned by
ComponentActivity.viewModels()
.
MyClass::class
: gives a reference to the Kotlin class MyClass
.
-
Receiver object passed to a function call becomes the implicit this
, so that its member methods can be accessed inside this same function.
-
An instance of the receiver is provided implicitely inside the function.
-
e.g. Canvas' onDraw lambda parameter.