It’s not PhD thesis material but a language for a job. Java feels very familiar to many different programmers because we preferred tried-and-tested things." - James Gosling in "The feel of Java", 1997 [https://pdfs.semanticscholar.org/5eb2/d00608ac08f4ca9f513066d8a81ea5358937.p df ]
type str = null //error var a: String? //nullable type String and String? are not the same. val length = a?.length //calculate length only if a is not null
: Int { return x + y; } //single line functions fun sum(x:Int, y:Int) = x + y; //optional parameters fun circumference(radius:Int = 1) = 2 * 3.14 * radius;
final by default. Primary constructor is explicit. open class Base { open fun methodToOverride() {} fun finalMethod() {} } class Extended : Base() { override fun methodToOverride() {} } //implementing interfaces class Extended : Base(), Runnable { override fun run() {} }
: Base(), Runnable { override fun run() {} } Multiple classes/interfaces can be defined in single file. Everything is an object. No primitives. There is no new operator: val obj = Extended() There is no static!
MM yyyy") return formatter.format(this) } //calling extension function val now = Date() String strDate = now.format() Extension functions are resolved statically
adapter.registerItemClickListener{ user -> updateUser(user)} Higher order functions along with extension functions: //in extensions.kt fun Adapter.registerItemClickListener(listener : (Int, Item)-> Unit){ } //calling adapter.registerItemClickListener{ user -> updateUser(user)}