kotlinc
kotlinc hello.kt -include-runtime -d hello.jar
java -jar hello.jar
var is a variable val is a value. It is immutable
val message = if (str == str1 {
"Correct"
} else {
"Wrong"
}
var str:String? = null
str? = "Give a value"
when(str) {
str1 -> print("Correct")
else -> print("Wrong")
}
val number:Int = try {
Integer.parseInt(int1)
} catch(e:NumberFormatException) {
null
}
for (i in 10 downTo 1 step 2 {
}
var ages = TreeMap<String, Int>()
ages = ["Kevin"] = 25
ages = ["Henry"] = 19
for((name, age) in ages) {
}
var reader = FileReader("filename") try { reader.read() } catch (e :IOException) {
} finally {
}
Don't need to be part of a class Are introduced with the 'fun' keyword Can have default parameters Can have named parameters Can 'extend' existing types Support function expressions
fun max(a: Int, b: Int): Int = if(a>b) a else b
======= <<<<<<< HEAD
=======
4ab3d12e16ad85130c6068af6743afa8632fa815