62,614
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args){
Map<String, String> map = new HashMap<>();
map.put("1", "one");
Set<Map.Entry<String, String>> entries = null;
try {
Field field = map.getClass().getDeclaredField("entrySet");
field.setAccessible(true);
entries = (Set<Map.Entry<String, String>>)field.get(map);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
System.out.println(entries); // null
System.out.println(map.entrySet()); // [1=one]
}
public Set<Map.Entry<K,V>> entrySet() {
Set<Map.Entry<K,V>> es;
return (es = entrySet) == null ? (entrySet = new EntrySet()) : es;
}