Kotlin is an official language for Android, which is announced in Google I/O . It's expressive, concise, and powerful. Best of all, it's interoperable with our existing Android languages and runtime.
Watch this here
Kotlin
button.setOnClickListener {
Toast.makeText(this, "Button Clicked", Toast.LENGTH_LONG).show();
}
JAVA
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast.makeText(this, "Button Clicked", Toast.LENGTH_LONG).show();
}
});
var a: String = "abc" // Declaring var 'a' as String ( If we declare var 'a' as String? then it can accept null
a = null // compilation error
fun Calculator(val1:Int,val2:Int,operation :(Int,Int)->Int){
val result = operation(val1,val2)
println(result)
}
fun main(args:Array){
val add: (Int,Int) -> Int ={ a,b -> a+b}
val sub: (Int,Int) -> Int ={ a,b -> a-b}
Calculator(5,5,add) // Print the value 10
Calculator(5,5,sub) // Print the value 0
}