Does this have Got something to do with precedence with right to left of = operator ?
Answer: No
And it's has got nothing to do With Integer Type too.
Why ? because
Here is what JSL say
String conversion applies only to an operand of the binary + operator
which is not a String when the other operand is a String.
In this single special case, the non-String operand to the + is
converted to a String (§5.1.11) and evaluation of the + operator
proceeds as specified in §15.18.1.
So even if you write any other type variable it will convert it Consider this snippet
public static void main(String...string){
double u=9.0;
System.out.println(u+"hi");
}
It gives me output
9.0hi
Now Coming to How ?
For the code snippet that i posted
Here is the part of compiled code of this
public static void main(java.lang.String...);
flags: ACC_PUBLIC, ACC_STATIC, ACC_VARARGS
Code:
stack=5, locals=3, args_size=1
0: ldc2_w #16 // double 9.0d
3: dstore_1
4: getstatic #18 // Field java/lang/System.out:Ljav
a/io/PrintStream;
7: new #24 // class java/lang/StringBuilder
10: dup
11: dload_1
12: invokestatic #26 // Method java/lang/String.valueOf
:(D)Ljava/lang/String;
15: invokespecial #32 // Method java/lang/StringBuilder.
"<init>":(Ljava/lang/String;)V
18: ldc #35 // String hi
20: invokevirtual #37 // Method java/lang/StringBuilder.
append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
23: invokevirtual #41 // Method java/lang/StringBuilder.
toString:()Ljava/lang/String;
26: invokevirtual #45 // Method java/io/PrintStream.prin
tln:(Ljava/lang/String;)V
So internally it invokes valueOf() method to convert double or non-string operand to String and than invokes append() to convert it into String totally .
Hope this helps you :)