英文:
Modifying Java Collection (List) Variable in Eclipse Debugger
问题
在Eclipse的调试器中,我可以更改普通变量的值,但现在我需要通过删除或添加元素来修改一个List。而且,它不能是一个空列表,它必须包含特定的项。
我右键单击变量,尝试'更改值',但以下操作不起作用:
new ArrayList<String>(Arrays.asList("333"));
==> 错误:"Arrays cannot be resolved"
和
list.remove("12345");
list.remove("67890");
==> 错误:生成的值(布尔值)与声明的类型(java.util.List)不兼容
还有其他想法吗?
英文:
In Eclipse's Debugger I can change the value of a plain variable, but now I need to modify a List by removing or adding elements. Also, it can't be an empty list, it must contain specific items.
I right-click on the variable and try 'Change Value', but the following don't work:
new ArrayList<String>(Arrays.asList("333"));
==> ERROR: "Arrays cannot be resolved"
and
list.remove("12345");
list.remove("67890");
==> ERROR: Generated value (Boolean) is not compatible with declared type (java.util.List)
Any other ideas?
答案1
得分: 2
如果您需要输入复杂表达式,使用“Debug Shell”视图可能会更容易。通过这种方式,您只需输入表达式或语句,将其突出显示,然后执行(或显示)它。您可能需要将对类(如“Arrays”)的引用替换为完全限定的类名。您还可以输入并执行多个语句,因此如果“Arrays.asList()”不方便,只需多次调用“add()”即可。
英文:
If you need to enter complex expressions, it's probably easier to use the "Debug Shell" view. Using this, you can simple enter an expression or statement, highlight it, and execute it (or display it). You may have to replace references to classes (like "Arrays") with the fully-qualified class name. You can also enter and execute multiple statements, so if "Arrays.asList()" isn't convenient, just call "add()" multiple times.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论