Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Singleton of Generic custom class: Cannot make a static reference ...

416044Sep 16 2010 — edited Sep 17 2010
I use singletons often for some static caches. Now I have a generic class "Cache<K, V>" that I want to subclass and use the singleton pattern:
public final class StaticCache<K, V> extends Cache<K, V> {
    static private StaticCache<K, V> instance = null;
}
But the declaration of the variable "instance" fails:

non-static class K cannot be referenced from a static context

non-static class V cannot be referenced from a static context

Of course, I don't want K,V static but only my instance. Is this possible at all?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 15 2010
Added on Sep 16 2010
12 comments
7,327 views