I am reading a book in which author used a code like this
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> Then he used code something like this
PoolObjectFactory<KeyEvent> factory = new PoolObjectFactory<KeyEvent>() { @Override public KeyEvent createObject() { return new KeyEvent(); } //end of createObject() }; keyEventPool = new Pool<KeyEvent>(factory, 100); I want to ask at the line PoolObjectFactory<KeyEvent> factory = new PoolObjectFactory<KeyEvent>() {..}; he didn't say implements PoolObjectFactory. Why? When you use interface then you use implements keyword?
Thanks