I'm developing some software where I'd like to allow the user to create and manage their own variables. I'd like to give the user the ability to create doubles, integers, and strings, and then manually set their values (all of this will be done through a UI). Right now I'm trying to decide on a model that would manage all of these user-defined variables.

My first thought was that it would be nice to have a Map that fetches variables by their name and use a "one-size-fits-all" 'Variable' class...

```
Map<String, Variable> myVars;

```

I thought to define the Variable class something like this...

```
public class Variable<T> 
{

private T value;

public void setValue(T value)
{
    this.value = value;
}

public T getValue()
{
    return value;
}

}

```

However, I think this approach requires me to define the map as `Map<String, Variable<T> >` but I don't want to choose a single type `T` for the entire map, but rather allow the map to contain a combination of integers, doubles, and strings.

A second thought was to create a container class that maintains three different maps, one each for strings, integers, and doubles. The three maps are insulated from the caller, and the caller merely needs to provide a String (the variable name) to a getter and the container would get the variable's value from the appropriate map. The container could also take care of issues like maintaining uniqueness of keys across all three maps.

A stub might look something like this...

```
public class VariableContainer {

private Map<String, Double> doubleVars = new HashMap();
private Map<String, String> stringVars = new HashMap();
private Map<String, Integer> intVars = new HashMap();

public Object get(String varName)
{
    if (doubleVars.containsKey(varName)) {
        return doubleVars.get(varName);
    } else if (stringVars.containsKey(varName)) {
        return stringVars.get(varName);
    } else if (intVars.containsKey(varName)) {
        return intVars.get(varName)
    } else {
        // varName not found
    }
}
}

```

However, now the caller of the `get` method must do inspection using `instanceof` to determine what kind of Object has been returned.

On that note, if inspection on the part of the caller is required, maybe it would be easiest to just stick with 

```
Map<String, Object>

```

and forget about an abstract `Variable` class or a container class.

Perhaps yet another option is to return a wildcard as described in the answer to this question:
[Avoiding Returning Wildcard Types](https://stackoverflow.com/questions/10507466/avoiding-returning-wildcard-types)

Does anyone have any thoughts or experience on a good way to approach this? Thanks for any input.