How to set and get using model in Hashmap?

2019-10-02 01:47发布

问题:

Model

private HashMap<String, Object> data;

    public Mode() {
        this.data = new HashMap<String, Object>();
    }

    public Object get(Mode value) {
        return this.data.get(value);
    }

    public void set(String key, Object value) {
        this.data.put(key, value);
    }

}

How do I set and get the value using this model?

回答1:

Try this

public Object get(String key) {
    return this.data.get(key);
}

public void set(String key, Object value) {
    this.data.put(key, value);
}