如何创建一个数组存贮接口阿

解决方案 »

  1.   

    i like ur icon lol, the guy is coool
      

  2.   

    你什么意思?就是一个数组 里面都是接口 比如ActionLister这样的接口  是吗?
    那不可能吧?  数组必须存储对象的实例 接口是抽象的  不会有实例的 更不要说存储接口了    我是这么理解的  楼下看看有没有办法
      

  3.   

    List [] list = new ArrayList[3];
      

  4.   

     Create a  second class B that contains an array of U. U是一个接口,这是一道题里的一句话
      

  5.   


    package Test;
    import java.util.*;
    public class qdbcool
    {
    private Animal a;
    public  Object[] fill(int length)
    {
    Object[] os=new Object[length];
    for(int i=0;i<os.length;i++)
    {
    os[i]=a;
    }
    return os;
    }
    public  void setAnimal(Animal a)
    {
    this.a=a;
    }
    public static void main(String[] args)throws Exception
    {
    qdbcool q=new qdbcool();
    System.out.println(Arrays.toString(q.fill(10)));
    q.setAnimal(new Dog());
    System.out.println(Arrays.toString(q.fill(10)));
    }
    }
    interface Animal{}
    class Dog implements Animal{}
    class Pig implements Animal{}正如test所见,数组其实保存的是一个引用,这引用甚至还没指向新的实例。
    那问题:接口有它自身的实例么?
      

  6.   

    这话的意思是 创建一个数组,它用来保存U类型的东西,说白了也就是拥有U特征的实例,即实现了
    U接口的实例
      

  7.   

        Create an interface U with three methods. Create a class A with a method
    that produces a reference to a U by building an anonymous inner class. Create a
    second class B that contains an array of U. B should have one method that
    accepts and stores a reference to a U in the array, a second method that sets a
    reference in the array (specified by the method argument) to null, and a third
    method that moves through the array and calls the methods in U. In main( ),
    create a group of A objects and a single B. Fill the B with U references
    produced by the A objects. Use the B to call back into all the A objects. Remove
    some of the U references from the B.
      

  8.   

    我正好无聊  给你翻译下:
    创建一个有3个方法的接口U。 创建一个类A,并且A中有一个方法,在这个方法里通过创建匿名内部类来产生一个U的引用。创建第二个类B,在B中有一个U型的数组,而且B中有一个方法,它能将U的引用接受并存储在数组中;另一个方法...通过这个,我觉得是接口类型的数组  而不是数组来存储接口...
      

  9.   

    U[] u=new U[20],是这样吗
      

  10.   

    就是 对象数组 吧.User[] u=new User[3]; 或者把对象存储到集合中List l=new ArrayList();
    l.add();
    .
    .
    .
      

  11.   

    现在的问题是将接口存储在数组中用A类的方法u()
    u[1]=A.u()
    其中public U u(){
    return new u(){
    public void value();
    }}
    有错,就是不知道怎么办?
      

  12.   

    肯定不对啊  new u()什么意思啊?