Map集合的遍历之键值对对象找键和值源码分析
package com.itheima.map;
public class Demo04_MapEntry {
/**
* @param args
* 解释一个Map.Entry
*/
public static void main(String[] args) {
//Entry其实是Map.Entry的一个子类对象
//(a):Map.Entry<String, Integer> en = it.next();//父类引用指向子类对象
//(b):Entry<String, Integer> en = it.next(); //直接获取的是子类对象
//对于a,是编译看左边(父类),运行在右边(子类),父类都是接口,子类都是有具体的实现内容
}
}
interface Inter {
interface Inter2 {
public void show();
}
}
class Demo implements Inter.Inter2 {
@Override
public void show() {
}
}
本文深入探讨了Java中Map集合的遍历方法,特别是通过Map.Entry接口获取键值对的过程。通过源码分析,解释了如何使用迭代器访问Map的每一个元素,并对比了父类引用与子类对象在编译和运行时的区别。
1726

被折叠的 条评论
为什么被折叠?



