- Defining package and importing similar to java but don't have to match directory and packages.
- Defining functions,
//very much similar to scala.
fun sum(a: Int, b: Int): Int{
return a+b
}
// inferred return type, inline body
fun sum(a: Int, b: Int) = a + b
//no meaningful return value. Unit can't omitted
fun printSum(a: Int, b: Int): Unit {
println("printing sum of $a and $b is ${a + b}")
}
- Variables
java | kotlin |
---|
Resources: