今天闲着没事看看 android v4包,结果发现一个类Pools.java,看了一下,从字面上的意思来看应该也是池,我自然而然的就会联想到线程池,看了一下,Pools类其实是对象池
里面维护了一个数组,废话不多说,看代码:
public final class Pools {
/**
* Interface for managing a pool of objects.
*
* @param <T> The pooled type.
*/
public static interface Pool<T> {
/**
* @return An instance from the pool if such, null otherwise.
*/
public T acquire();
/**
* Release an instance to the pool.
*
* @param instance The instance to release.
* @return Whether the instance was put in the pool.
*
* @throws IllegalStateException If the instance is already in the pool.
*/
public boolean release(T instance);
}
private Pools() {
/* do nothing - hiding constructor */
}
/**
* Simple (non-