This document provides a quick comparison of Kotlin to Java.
Fixes
Safety problems in Java that are fixed in Kotlin:
- Null references are controlled by the type system, i.e. Kotlin has no NPE's
- Full type information is retained at runtime, i.e. better reflection/safer instanceof-checks
- No raw types
- Arrays in Kotlin are invariant
Usability problems in Java that are fixed in Kotlin:
- Kotlin has higher-order functions, aka closures
- And with inlining they are cheap
- Use-site variance without wildcards
- Declaration-site variance
- Kotlin has no checked exceptions
What Java has and Kotlin has not
- Checked exceptions
- Primitive types that are not objects
- Static members
- Non-private fields
- Type erasure
- Wildcard-types
What Kotlin has and Java has not
- Function literals + Inline functions = performant custom control structures
- Null-safety
- Smart casts
- String templates
- Properties
- Primary constructors
- Mixins and First-class delegation
- Extension functions
- Type inference for variable and property types
- Singletons
- Declaration-site variance & Type projections
- Modules
- Range expressions
- Pattern matching
- Generic types retained at runtime
- Operator overloading
- Class objects
What's next
Labels:
None
