- Java interoperability
- Type inference
- Smart cast
- Method references
- inline if-else and try-catch
- Expression body methods
- Default closed classes
- Null safety
- default parameters and named parameters
- infix methods
- Extension functions
- String templates
- Compile time constants using
const
- lateinit and delegated properties
- Operator overloading
- Arrays
- Collections
- Object expressions and declarations (Singleton, anonymous objects etc.)
- Range expressions
- Data classes
- Higher-Order Functions and Lambdas
Property delegates don’t have to implement any interface, but they have to provide a getValue() function (and setValue()
val lazyGuy: LazyGuy by lazy { LazyGuy("is always late") }
Helpful functions right out of the box.
fun toBeImplemented() {
TODO("Your reason")
}
Written as expression body
fun toBeImplemented() = TODO("Your reason")
class Pet(val name: String)
class Dog(name: String):Pet(name) // WON'T WORK: Pet is default final
We need to specify the open
keyword
open class Pet(val name: String)
fun testThis(str: String) = if(str.lenght > 2) "Test1" else "Test2"