java - 如何在 POJO 类中使用 HashMap 并检索它?
问题描述
我应该在我的 POJO 中哪里写 hashmap?
我试过我的构造函数,我不知道如何使用哈希图?特别是在我的 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;
}
}
解决方案
你的问题令人困惑。
你想拥有一个 HashMap 私有数据成员吗?你总是可以这样做:
public class CurrentAttendance {
private Map something = new HashMap();
public Map getSomething() { return Collections.unmodifiableMap(this.something); }
}
推荐阅读
- javascript - 当值是 Camunda 中的数组时如何在脚本任务中设置变量
- multithreading - JDK 中的异步 NIO 是如何工作的?
- expo - 对 androidmanifest 进行一些更改后重新编译 apk?
- bash - 带有命令替换的局部变量赋值行为异常
- node.js - .npm 缓存与 node_modules 大小
- jquery - 动态按钮不会在 jQuery 中打开模式
- html - 在扩展的切换引导导航栏中对齐项目
- spring - AliasQuery 在 Spring Data Elasticsearch 4.1 中已弃用
- php - 是否可以覆盖 Doctrine Entity 中的表名?
- ghost-blog - Ghost博客检查用户是否使用嵌入博客文章登录