0

Intellij IDEA is complaining about Generic array creation

public abstract class BaseImageLoader<CacheItem>
{
    private ImageLoaderThread[] workerThreads;

    public BaseImageLoader(Context context)
    {
        ...
        workerThreads = new ImageLoaderThread[DEFAULT_CACHE_THREAD_POOL_SIZE];//Generic array creation error
        ...
    }
}

ImageLoaderThread is in fact a subclass of java.lang.Thread, its not generic
I dont get what im doing wrong

this works fine:

Thread[] threads = new Thread[DEFAULT_CACHE_THREAD_POOL_SIZE];

ImageLoaderThread class

private class ImageLoaderThread extends Thread
{
    /**
     * The queue of requests to service.
     */
    private final BlockingQueue<ImageData> mQueue;
    /**
     * Used for telling us to die.
     */
    private volatile boolean mQuit = false;

    /**
     * Creates a new cache thread.  You must call {@link #start()}
     * in order to begin processing.
     *
     * @param queue    Queue of incoming requests for triage
     */
    public ImageLoaderThread(BlockingQueue<ImageData> queue)
    {
        mQueue = queue;
    }

    /**
     * Forces this thread to quit immediately.  If any requests are still in
     * the queue, they are not guaranteed to be processed.
     */
    public void quit()
    {
        mQuit = true;
        interrupt();
    }

    @Override
    public void run()
    {
        android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
        ImageData data;
        while (true)
        {
            try
            {
                // Take a request from the queue.
                data = mQueue.take();
            }
            catch (InterruptedException e)
            {
                // We may have been interrupted because it was time to quit.
                if (mQuit)
                {
                    return;
                }
                continue;
            }
            ...
            //other unrelated stuff
        }
    }
}
pedja
  • 2,825
  • 3
  • 30
  • 47

0 Answers0