Can Kotlin be defined a strongly typed language?
Asked Answered
G

1

6

From the definition of strongly-typed language:

A strongly-typed programming language is one in which each type of data (such as integer, character, hexadecimal, packed decimal, and so forth) is predefined as part of the programming language and all constants or variables defined for a given program must be described with one of the data types (source)

From kotlin documentation, I can understand that kotlin is a statically typed language because the type of the variable is known at compile time, but what about strongly or weakly typed? I can't find any clear response googling. As far as I understood Kotlin should be equally strongly typed as Java because it compiles down to Java byte code, but I'm not 100% sure. Please help me to understand if I'm on the right way.

Gentleman answered 11/1, 2019 at 9:48 Comment(1)
It has type inference, but the types cannot be reassigned, so it's strict.Murrah
Z
16

Weakly-typed languages feature implicit conversions between incompatible types while strongly-typed languages disallow it.

Kotlin doesn't feature implicit conversions between types - which makes it strongly statically typed.

Zebe answered 11/1, 2019 at 9:51 Comment(1)
Mmm. In fact, Kotlin is even more strongly typed than Java, in that it lacks Java's implicit numeric conversions (widening int to long, &c). Including nullability in the type system could also be seen as making it stronger.Putter

© 2022 - 2024 — McMap. All rights reserved.