String is a Class in Java.
int is a primitive type.
You can't force cast a primitive type to an Object.
Operand "+" is a special operand, for example:
public class TestSimplePlus
{
public static void main(String[] args)
{
String s = "abc";
String ss = "ok" + s + "xyz" + 5;
System.out.println(ss);
}
}
let's take a look at the decompilation code:
package string;
import java.io.PrintStream;
public class TestSimplePlus
{
public TestSimplePlus()
{
// 0 0:aload_0
// 1 1:invokespecial #8 <Method void Object()>
// 2 4:return
}
public static void main(String args[])
{
String s = "abc";
// 0 0:ldc1 #16 <String "abc">
// 1 2:astore_1
String ss = (new StringBuilder("ok")).append(s).append("xyz").append(5).toString();
// 2 3:new #18 <Class StringBuilder>
// 3 6:dup
// 4 7:ldc1 #20 <String "ok">
// 5 9:invokespecial #22 <Method void StringBuilder(String)>
// 6 12:aload_1
// 7 13:invokevirtual #25 <Method StringBuilder StringBuilder.append(String)>
// 8 16:ldc1 #29 <String "xyz">
// 9 18:invokevirtual #25 <Method StringBuilder StringBuilder.append(String)>
// 10 21:iconst_5
// 11 22:invokevirtual #31 <Method StringBuilder StringBuilder.append(int)>
// 12 25:invokevirtual #34 <Method String StringBuilder.toString()>
// 13 28:astore_2
System.out.println(ss);
// 14 29:getstatic #38 <Field PrintStream System.out>
// 15 32:aload_2
// 16 33:invokevirtual #44 <Method void PrintStream.println(String)>
// 17 36:return
}
}
As we can see, "+" operand is to call StringBuilder.append() while at least one of the parameters is string
Hope you get it!