What are the key aspects of a strongly typed language?

前端 未结 8 2063
后悔当初
后悔当初 2020-12-09 17:26

What makes a language strongly typed? I\'m looking for the most important aspects of a strongly typed language.

Yesterday I asked if PowerShell was strongly typed, b

8条回答
  •  北海茫月
    2020-12-09 17:38

    The key is to remember that there is a distinction between statically typed and strongly typed. A strongly typed language simply means that once assigned, a given variable will always behave as a certain type until it is reassigned. By definition statically typed languages like Java and C# are strongly typed, but so are many popular dynamic languages like Ruby and Python.

    So in a strongly typed language

    x = "5"
    

    x will always be a string and will never be an integer.

    In certain weakly typed languages you could do something like

    x = "5"
    y = x + 3
    // y is now 8
    

提交回复
热议问题