# Comparison to Java ## Some Java issues addressed in Kotlin Kotlin fixes a series of issues that Java suffers from: * Null references are [controlled by the type system](null-safety.html). * [No raw types](java-interop.html#java-generics-in-kotlin) * Arrays in Kotlin are [invariant](arrays.html) * Kotlin has proper [function types](lambdas.html#function-types), as opposed to Java's SAM-conversions * [Use-site variance](generics.html#use-site-variance-type-projections) without wildcards * Kotlin does not have checked [exceptions](exceptions.html) * [Separate interfaces for read-only and mutable collections](collections-overview.html) * Kotlin provides [a performant and ergonomic replacement for Enum.values()](enum-classes.html#find-enum-constants) ## What Java has that Kotlin does not * [Checked exceptions](exceptions.html) * [Primitive types](types-overview.html) that are not classes. The byte-code uses primitives where possible, but they are not explicitly available. * [Static members](classes.html) are replaced with [companion objects](object-declarations.html#companion-objects), [top-level functions](functions.html), [extension functions](extensions.html#extension-functions), or [@JvmStatic](java-to-kotlin-interop.html#static-methods). * [Wildcard-types](generics.html) are replaced with [declaration-site variance](generics.html#declaration-site-variance) and [type projections](generics.html#type-projections). * [Ternary-operator a ? b : c](control-flow.html#if-expression) is replaced with [if expression](control-flow.html#if-expression). * [Records](https://openjdk.org/jeps/395) * package-private [visibility modifier](visibility-modifiers.html) Note: Kotlin doesn't have pattern matching, but [smart casts in Kotlin](typecasts.html#smart-casts) provide similar functionality to [pattern Matching in Java](https://openjdk.org/projects/amber/design-notes/patterns/pattern-matching-for-java). Learn more in this [video on the official Kotlin by JetBrains channel](https://www.youtube.com/watch?v=yJDoa42X-wQ). ## What Kotlin has that Java does not * [Lambda expressions](lambdas.html) + [Inline functions](inline-functions.html) = performant custom control structures * [Extension functions](extensions.html) * [Null-safety](null-safety.html) * [String templates](strings.html) * [Properties](properties.html) * [Primary constructors](classes.html) * [First-class delegation](delegation.html) * [Type inference for variable and property types](types-overview.html) (Java 10: [Local-Variable Type Inference](https://openjdk.org/jeps/286)) * [Singletons](object-declarations.html) * [Declaration-site variance & Type projections](generics.html) * [Range expressions](ranges.html) * [Operator overloading](operator-overloading.html) * [Companion objects](classes.html#companion-objects) * [Data classes](data-classes.html) * [Coroutines](coroutines-overview.html) * [Top-level functions](functions.html) * [Parameters with default values](functions.html#parameters-with-default-values) * [Named parameters](functions.html#named-arguments) * [Infix functions](functions.html#infix-notation) * [Expect and actual declarations](https://kotlinlang.org/docs/multiplatform/multiplatform-expect-actual.html) * [Explicit API mode](whatsnew14.html#explicit-api-mode-for-library-authors) and [better control of API surface](opt-in-requirements.html) Note: Java doesn't have smart casts, but [pattern matching](https://openjdk.org/projects/amber/design-notes/patterns/pattern-matching-for-java) provides similar functionality to [smart casts in Kotlin](typecasts.html#smart-casts). Learn more in this [video on the official Kotlin by JetBrains channel](https://www.youtube.com/watch?v=yJDoa42X-wQ). ## What's next? Learn how to: * Perform [typical tasks with strings in Java and Kotlin](java-to-kotlin-idioms-strings.html). * Perform [typical tasks with collections in Java and Kotlin](java-to-kotlin-collections-guide.html). * [Handle nullability in Java and Kotlin](java-to-kotlin-nullability-guide.html).