Wildcards in the class definition

I have a class which extends java.util.Hashtable. The Key is String and value is a HttpClient object, but in future I can have Values as objects other than HttpClient. I was thinking to use a wildcard for storing the value, but the syntax isn't right. What is the right way to do it? Thanks.

publicclass MyHashtable<String, ?>extends Hashtable{

public MyHashtable(){

........

}

This works:

publicclass MyHashtable<String, HttpClient>extends Hashtable{

public MyHashtable(){

........

}

[980 byte] By [leostar_10a] at [2007-11-27 11:36:18]
# 1

> public class MyHashtable<String, ?> extends Hashtable

public class MyHashtable<String, T> extends Hashtable<String, Object>

or possibly

public class MyHashtable extends Hashtable<String, Object>

Why do you need this subclass at all?

ejpa at 2007-7-29 17:08:00 > top of Java-index,Core,Core APIs...
# 2

Something like:

public class MyHashtable<T> extends Hashtable<String, T>

Would be better imo, as it allows you to specify a data type if you want.

Anyway, why do you want to subclass Hashtable ?

And you may use HashMap or Collections.concurrentMap(map) if need synchronization.

ibanna at 2007-7-29 17:08:00 > top of Java-index,Core,Core APIs...
# 3

> if need synchronization.

If you don't need synchronization ...

ejpa at 2007-7-29 17:08:00 > top of Java-index,Core,Core APIs...