distums / distums.github.io

my personal blog
https://distums.github.io/
0 stars 0 forks source link

strong/weak type vs static/dynamic type #19

Open distums opened 7 years ago

distums commented 7 years ago

静态/动态类型表示变量是否与类型绑定

String str = "Hello";  //statically typed as string
str = 5;               //would throw an error since java is statically typed
str = "Hello" # it is a string
str = 5       # now it is an integer; perfectly OK

强/弱类型表示是否允许类型间的隐式转换

str = 5 + "hello" 
# would throw an error since it does not want to cast one type to the other implicitly. 
$str = 5 + "hello"; // equals 5 because "hello" is implicitly casted to 0 
// PHP is weakly typed, thus is a very forgiving language.