修改 Eclipse 调试器中的 Java 集合(List)变量

huangapple go评论78阅读模式
英文:

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不兼容

还有其他想法吗?

修改 Eclipse 调试器中的 Java 集合(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&lt;String&gt;(Arrays.asList(&quot;333&quot;));

==&gt; ERROR: &quot;Arrays cannot be resolved&quot;

and

list.remove(&quot;12345&quot;);
list.remove(&quot;67890&quot;);

==&gt; ERROR: Generated value (Boolean) is not compatible with declared type (java.util.List)

Any other ideas?

修改 Eclipse 调试器中的 Java 集合(List)变量

答案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.

huangapple
  • 本文由 发表于 2020年10月19日 23:37:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/64430629.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定