回 帖 发 新 帖 刷新版面

主题:[讨论]关于setText()的问题!

setText()中不是要用String类型的吗?为什么也可以这样写:setText("nihao"+x)  ??  x是int类型。

回复列表 (共2个回复)

沙发

You need to understand what is String concatenation.

"nihao"+x is String type

You can try:

String s = "nihao" + 5; // compiled
System.out.println(s);  // nihao5 printed out

板凳

这里的 + 是连接运算符,表示将String与int(或其它基本数据类型)连接为一个字符串。

我来回复

您尚未登录,请登录后再回复。点此登录或注册