Reputation: 640
I want to customize the way the IntelliJ debugger display the value of Set
objects. Therefore I created a new Java Data Type Renderers
in the Customize Data Views
dialog and pasted this code into the Use following expression
field:
String s = "";
if (this.size() > 0) {
Iterator iterator = this.iterator();
if (iterator.hasNext()) {
s += iterator.next();
if (iterator.hasNext()) {
s += ", ";
do {
s += iterator.next();
} while (iterator.hasNext());
}
}
}
return s;
However following error is shown in the debugger: Unable to evaluate the expression Initializer for 's' has incompatible type
.
How should I write a multiline expression into the field so my above code works properly?
Upvotes: 1
Views: 876
Reputation: 2791
If you are using Java 8 you can use String.join(", ", this)
It should look something like this.
If you are using an older version of Java you can use.
StringBuilder sb = new StringBuilder();
Iterator<?> iter = this.iterator();
if (iter.hasNext())
sb.append(iter.next().toString());
while (iter.hasNext()) {
sb.append(", ");
sb.append(iter.next().toString());
}
return sb.toString();
IntelliJ highligted the iterator
code in red but it still works.
Upvotes: 1