刚才发了个帖子--数组不是对象。结贴后抛出了异常。所以又要再发一遍。
看下面代码:    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 提到:还有:
不知道后三步又是什么呢?

解决方案 »

  1.   

    数组当然是Object,java中任何东西都是Object,接口除外
    当你传一个数组进去的时候,肯定是调用数组参数的重载版本,编译器根据形参确定重载哪一个方法,找的是最接近实参的形参版本
      

  2.   

    晕,不好意思。午饭前有点RUSH,这个问题偶回答的也不对。昨天总是遇到泛型的问题,所以有点混。
    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
      

  3.   

    首先:a是个对像。其次:a是个数组。再次:是个String形的数组。
     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");
        }
      

  4.   

    这显然是不正确的,不管什么类型的Array都只是继承自Object,Object 和String只是他的Components type
    数组还实现Cloneable和Serialzable接口
      

  5.   

    哎,总以为自己Java学的也算不错的了。SCJP也考了90几分。
    http://blog.csdn.net/Brodie/archive/2009/10/31/4750190.aspx