以下代码来自 Bates 和 Sierra:
public class Book {
private String title; // instance reference variable
public String getTitle() {
return title;
}
public static void main(String [] args) {
Book b = new Book();
String s = b.getTitle(); // Compiles and runs
String t = s.toLowerCase(); // Runtime Exception!
}
}
为什么不会String t = s.toLowerCase()
导致运行时异常String s = b.getTitle()
?