如何在POJO类中使用HashMap并检索它?

时间:2018-12-23 15:02:16

标签: java hashmap

我应该在我的POJO中写哈希图吗?

我尝试过使用构造函数,但我不知道如何使用哈希图? 特别是在我的POJO课上->

public class CurrentAttendance {

    private String name;
    private int userCount;
    private int currentAttendance;
    private long firstJoin;
    private Object timestamp;

    //empty constructor
    public CurrentAttendance() {
    }

    //entry values
    public CurrentAttendance(String name, int userCount, int currentAttendance, long firstJoin, Object timestamp) {
        this.name = name;
        this.userCount = userCount;
        this.currentAttendance = currentAttendance;
        this.firstJoin = firstJoin;
        this.timestamp = timestamp;
    }

这是我的吸气剂

    public String getXName(){
        return name;
    }
    public int getUserCount(){
        return userCount;
    }
    public int getCurrentAttendance() {
        return currentAttendance;
    }
    public long getFirstJoin(){
        return firstJoin;
    }
    public Object getTimestamp(){
        return timestamp;
    }
}

1 个答案:

答案 0 :(得分:0)

您的问题令人困惑。

您是否想要一个HashMap私有数据成员?您可以随时这样做:

public class CurrentAttendance {
    private Map something = new HashMap();

    public Map getSomething() { return Collections.unmodifiableMap(this.something); }
}