3 ms·
I don't think that is a counterexample. "" + 5 is defined by translation to new StringBuilder("").append(5) which statically resolves to the method
by samstokes 16y ago
I don't think that is a counterexample.
"" + 5
is defined by translation to
new StringBuilder("").append(5)
which statically resolves to the method StringBuilder.append(int), whose implementation explicitly converts 5 to a string.
Java does offer a counterexample to "strong typing means no implicit conversion", though:
String s = "foo";
Object o = s;
I just implicitly converted a String to an Object, which the GP's definition disallows.
Of course you can fix up the definition for Java by adding the proviso "except upcasting a derived type to a superclass of that type", but the fact that you have to add a language-specific proviso indicates why there's no accepted common definition.
But at least with that proviso our definition works for all object-oriented languages, right? Well, actually it still doesn't even work for Java, because since Java 1.5 you can say:
int i = 2;
Integer i2 = i;
So Java needs an exception for upcasting, and for autoboxing, and we probably should worry about exactly what type we think 'null' has...