Comparison to Java Programming Language
Some Java issues addressed in Kotlin
Kotlin fixes a series of issues that Java suffers from:
- Null references are controlled by the type system.
- No raw types
- Arrays in Kotlin are invariant
- Kotlin has proper function types, as opposed to Java's SAM-conversions
- Use-site variance without wildcards
- Kotlin does not have checked exceptions
What Java has that Kotlin does not
- Checked exceptions
- Primitive types that are not classes - The byte-code uses primitives where possible, but they are not explicitly available.
- Static members - replaced with companion objects, top-level functions, extension functions, or @JvmStatic.
- Wildcard-types - replaced with declaration-site variance and type projections.
-
Ternary-operator
a ? b : c
- replaced with if expression.
What Kotlin has that Java does not
- Lambda expressions + Inline functions = performant custom control structures
- Extension functions
- Null-safety
- Smart casts
- String templates
- Properties
- Primary constructors
- First-class delegation
- Type inference for variable and property types
- Singletons
- Declaration-site variance & Type projections
- Range expressions
- Operator overloading
- Companion objects
- Data classes
- Separate interfaces for read-only and mutable collections
- Coroutines
© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/docs/reference/comparison-to-java.html