【发布时间】:2013-08-03 17:27:33
【问题描述】:
public static void main(String[] args) {
String s1 = null;
String s2;
s1.trim(); //No compile error. But run time error
s2.trim(); //compile error.
}
在上面的代码中,初始化后s1没有赋值
编译器知道s1 是null。那为什么不显示s1.trim() 的编译错误,比如s2?
【问题讨论】:
-
也许题外话,但如果你使用 eclipse,你会收到警告
标签: java string compiler-errors variable-assignment