有没有办法检查 Eclipse 中的 map/set 条目?

Is there a way to inspect map/set entries in eclipse?

我有以下代码

Map<String, Employee> map1 = new HashMap<String, Employee>();
map1.put("delKey", new Employee());
map1.put("delKey1", new Employee());

当我使用 show logical structure 检查 variables view 下的 map1 时,我只是将值视为 Employee 而不是对象,这样我就可以像下面这样检查更多的 employee 对象

有什么方法可以在 eclipse map/set 条目下调试 key/value

使用调试器。在要查看地图状态的行上放置一个断点(它必须在范围内),然后 运行 调试模式下的程序。

程序会停在有断点的那一行。在 window Variable 中,您应该能够看到范围内的所有变量。

代码似乎是正确的。您是否在 Employee class 中创建了任何属性?我尝试了以下方法:

public class Employee {
    private String name;

    public Employee() {
        super();
        // TODO Auto-generated constructor stub
    }

    public Employee(String name) {
        super();
        this.name = name;
    }

}

调试时我可以看到这些值:

您还可以做一件事来覆盖员工中的 toString() 方法 class 并为您提供自定义打印对象的方式。记录代码。员工价值观将在控制台中描绘。

首选方法是在调试模式下检查。您的调试器没有显示员工属性,可能 class 中会有 none,请检查您的代码。