3 ms·
Java is strongly typed. As a counterexample, here's some valid java: String str = ""+5;
by Xk 16y ago
Java is strongly typed. As a counterexample, here's some valid java:
String str = ""+5;
- xiongchiamiov 16y agoThe point I was attempting to make is that Java (and all other languages that I know of) are both strongly and weakly typed.
- samstokes 16y agoI 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...