呵呵,看看properties的源码:
/**
* Returns an enumeration of all the keys in this property list,
* including distinct keys in the default property list if a key
* of the same name has not already been found from the main
* properties list.
*
* @return an enumeration of all the keys in this property list, including
* the keys in the default property list.
* @see java.util.Enumeration
* @see java.util.Properties#defaults
*/
public Enumeration propertyNames() {
Hashtable h = new Hashtable();
enumerate(h);
return h.keys();
}接口本身是不能被实例化的,当然不能直接调用。
/**
* Returns an enumeration of all the keys in this property list,
* including distinct keys in the default property list if a key
* of the same name has not already been found from the main
* properties list.
*
* @return an enumeration of all the keys in this property list, including
* the keys in the default property list.
* @see java.util.Enumeration
* @see java.util.Properties#defaults
*/
public Enumeration propertyNames() {
Hashtable h = new Hashtable();
enumerate(h);
return h.keys();
}接口本身是不能被实例化的,当然不能直接调用。
propertyNames()实例化一个对象返回。
调用的实际是返回的对象里的方法
p.propertyNames();这个方法返回来的对象就是实例化的Enumeration
Enumeration enum = new Enumeration();
但是
p.propertyNames();返回的是实例,传reference给enum。
看看多态,向上转型就知道了