我正在读一本书,其中作者使用了这样的代码
public class Pool<T> {
public interface PoolObjectFactory<T> {
public T createObject();
}
private final List<T> freeObjects;
private final PoolObjectFactory<T> factory;
private final int maxSize;
public Pool(PoolObjectFactory<T> factory, int maxSize) {
this.factory = factory;
this.maxSize = maxSize;
this.freeObjects = new ArrayList<T>(maxSize);
} //end of constructor
} //end of class Pool<T>
然后他使用了类似这样的代码
PoolObjectFactory<KeyEvent> factory = new PoolObjectFactory<KeyEvent>() {
@Override
public KeyEvent createObject() {
return new KeyEvent();
} //end of createObject()
};
keyEventPool = new Pool<KeyEvent>(factory, 100);
我想在PoolObjectFactory<KeyEvent> factory = new PoolObjectFactory<KeyEvent>() {..};
他没说的那条线上问implements PoolObjectFactory
。为什么?当您使用界面时,您使用implements
关键字?
谢谢