刚才发了个帖子--数组不是对象。结贴后抛出了异常。所以又要再发一遍。
看下面代码: public static void main(String[] args) {
String[] a = {};
test(a);
}
private static void test(Object ob){
System.out.println("OB");
}
// private static void test(Object[] ob){
// System.out.println("AR");
// }
当前输出:OB
打开 test(Object[] ob) 方法后呢? 当然这个不是“多态”的表现。(这个错误让刚才回帖的 Brodie 郁闷了~~不好意思~~呵呵~~)
刚才 Brodie 提到:还有:
不知道后三步又是什么呢?
看下面代码: public static void main(String[] args) {
String[] a = {};
test(a);
}
private static void test(Object ob){
System.out.println("OB");
}
// private static void test(Object[] ob){
// System.out.println("AR");
// }
当前输出:OB
打开 test(Object[] ob) 方法后呢? 当然这个不是“多态”的表现。(这个错误让刚才回帖的 Brodie 郁闷了~~不好意思~~呵呵~~)
刚才 Brodie 提到:还有:
不知道后三步又是什么呢?
当你传一个数组进去的时候,肯定是调用数组参数的重载版本,编译器根据形参确定重载哪一个方法,找的是最接近实参的形参版本
String[]和Object[]都是Clonable的子类,但String[]是不是Object[]的子类?很难证明。大家可以讨论一下。调用方法五步,准确的文档。
At run time, method invocation requires five steps. First, a target reference may be computed. Second, the argument expressions are evaluated. Third, the accessibility of the method to be invoked is checked. Fourth, the actual code for the method to be executed is located. Fifth, a new activation frame is created, synchronization is performed if necessary, and control is transferred to the method code.链接, http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#45677
public static void main(String[] args) {
String[] a = {};
test(a);
}
private static void test(Object ob){
System.out.println("OB");
}
private static void test(Object[] ob){
System.out.println("AR");
} private static void test(String[] ob){
System.out.println("ss");
}
数组还实现Cloneable和Serialzable接口
http://blog.csdn.net/Brodie/archive/2009/10/31/4750190.aspx