Java is still strongly typed, despite your example. The code is equivalent to
String s = "hello ";
s = s + 4;
and Java will convert the 4
into a string, then perform the string concatenation. This is a language feature.
In Python, however, you cannot use +
to concatenate 4
to your string, because the language will not take the liberty of converting it to a str
. As you point out, Java does this for you under the hood.