What is a strongly typed language?

What is a strongly typed language?

+4
source share
5 answers

Strictly typed languages ​​provide text input in all interacting data.

for instance

int i = 3
string s = "4"

Now that you are using i, you can only interact with it as an integer type. This means that you are limited to using methods that work with integers.

As for the string s, you can only interact with it as a string type. You can link it to another line, print it, etc. However, although it contains this “4” character, you cannot add to an integer without using any function to convert the string to an integer type.

In a dynamically typed language, you have much more flexibility:

i = 3
s = "4"

; , , . - , s - , , . , + s; , + s = 7; s int . "34", int +, .

. - , ; , . , + s, s int, , s, 7, s int . , , , s; , . , , .

+10

, , .

:

String myString = "Fred";

, "myString" ​​ .

:

x = 10;
x = "Fred";

( ).

+3

, , , " " . , .

+3

" " . , ?

, . , string number .

string s;
number n;
s + n;          <-- Type error.

. , / / , .

, , :

s + (string)n;  <-- Allowed, as (number) has been explicitly
                    casted to (string), so variable types match.

.

s + n;          <-- Allowed, where the language will cast
                    the (number) to (string)

Perhaps a “strongly typed language” refers to a very strongly typed language in which there are more stringent restrictions on how operations can be performed on variables of different types.

+3
source

where it '1' + 3will be illegal, because it adds a string to an integer.

0
source

All Articles