《Java Language Specific》中看到这么一句话:
A variable of an interface type can hold a null reference or a reference to an instance of any class that implements the interface.
”A variable of an interface“,恩,这个激发了自己的遐想,接口是不是也可以直接声明变量呀?
自己是没见过。请问下。作者: 崔浩 时间: 2011-11-23 17:46
接口变量被赋值于子类实现的对象
好比在定义方法的时候可以是接口的变量,在实际调用的时候,传入子类的对象。
集合中也是有很多的,List list=new ArrayList();声明了一个List接口类型的变量,但是赋值了ArrayList实现类的子类的对象作者: 郝亚平 时间: 2011-11-23 17:56