Professional Documents
Culture Documents
Preferences (OSX)
or Settings (Windows/Linux)
> Plugins
> Code
JAVA Kotlin
}
Lazy Lambdas
JAVA Kotlin
mButton.setOnClickListener(new View.OnClickListener() { mButton.setOnClickListener {
Toast.makeText(this, "Hello Droidcon!", Toast.LENGTH_SHORT).show()
@Override
}
public void onClick(View v) {
Toast.makeText(this, "Hello Droidcon!",
Toast.LENGTH_SHORT).show();
}
};
Set with “with()”
JAVA Kotlin
when (x) {
0 -> print("x is 0") // x == 0
in 1..10 -> print("x is in the range") // x inside range 1 - 10
in validNumbers -> print("x is valid") // x is in a collection “validNumbers”
!in 10..20 -> print("x is outside the range") // x is outside range 10 - 20
else -> print("none of the above") // default case
}
Exclusive Extensions
Usage:
incrementSteps(5) // Returns 6
incrementSteps(5, 3) // Returns 8
Funny Functions: Named Arguments
fun incrementSteps(currentSteps: Int, increment: Int = 1): Int {
return currentSteps + increment
}
Usage:
Usage:
doubleSteps(5) // Returns 10
Funny Functions: Varargs (Variable Arguments)
fun getSum(vararg numbers: Int): Int {
var sum = 0
for (number in numbers) {
sum += number
}
return sum
}
Usage:
getSum(1, 2, 3) // Returns 6
getSum(1, 2, 3, 4, 5) // Returns 15
More Kotlin Awesomeness
https://kotlin.link
http://try.kotlinlang.org
https://github.com/Kotlin/kotlin-koans
https://www.facebook.com/groups/1289612087746759/
Thank You