public class Test {
public static void main(String[] args) {
String str = null;
for(int i=0; i<5; i++){
str += i;
}
System.out.println(str);
}
}上面的代码执行后为何是
null01234
创建线程时,继承Thread类会导致线程与线程任务的耦合度高
这句要怎么理解,难道实现Runnable就不会吗?
------解决思路----------------------
看源码,println调用了print,其内容如下
public void print(String s) {
if (s == null) {
s = "null";
}
write(s);
}