两个初始化之间有什么区别:
Object x = new String();
String x = new String();
Run Code Online (Sandbox Code Playgroud)
在java中
谢谢!
Object x = new String(); // pointing to a String and saying - Hey, Look there! Its an Object
String x = new String();// pointing to a String and saying - Hey, Look there! Its a String
Run Code Online (Sandbox Code Playgroud)
更重要的是:可以访问的String方法取决于引用.例如 :
public static void main(String[] args) {
Object o = new String();
String s = new String();
o.split("\\."); // compile time error
s.split("\\."); // works fine
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
817 次 |
| 最近记录: |