Anton Rutkevich
JunoLab
safe &
readable
Kotlin
Libraries
// Constant
val a: Int = 1
// Variable
var b: Int = 2
b++
// Nullable variable
var c: String? = null
c?.charAt(0) // returns Char?
val list: List<String>
= arrayListOf("1", "2", "3")
list.add("4") // No such method :)
val mutableList: MutableList<String>
= arrayListOf("4", "5", "6")
mutableList.add("7") // OK
// Lambda instead of anonymous class
val button: Button = ...
button.setOnClickListener {
// Do something
}
val list =
= arrayListOf("one", "two", "three")
list.filter {
it.length() < 5
}.map {
it.reverse()
}.forEach {
Log.d(TAG, "String: ${it}")
}
data class Purchase (
val url: String,
val id: String,
val amount: Int = 1
)
// Inside a method...
purchase = purchase.copy(amount = newAmount)
fun textColorRes(): Int {
return if (isValid()) {
R.color.green
} else {
R.color.red
}
}
properties
public
protected
open
ternary operator :(
write
read
test
RxJava
Dagger 2
Retrofit
Gson