Hi,

 

I make use of the Debuggers ‘Variables’ tab and make the ‘String value: String representation of the value” column active. For some reason it is off by default.

 

Then, for any complex class I ensure that the @Override public String toString() {} method is defined to publish all the details about the class. The toString() method is rarely needed for these complex classes and so I make use of it as a debugging tool. I always make sure that I have overridden this method as part of setting up a new class.

 

As you note, a simple array (e.g. ArrayList<>()) only shows the size of the array in the String value column (e.g. size = 5). In this case, I wrap the array inside a record and override the toString() method there. The debugger then uses the records toString() method in the stringValue cell, showing you the full array.

 

e.g.

 

  record StringList (List<String> data) {

    @Override

    public String toString () {

      StringBuilder result = new StringBuilder();

      boolean isFirst = true;

      for (String value : data) {

        if (isFirst) {

          isFirst = false;

        }

        else {

          result.append(',');

          result.append(System.lineSeparator());

        }

        result.append(value);

      }

      return result.toString();

    }

  }

  

  class MyClass {

    private StringList strings;

   

    MyClass() {

      this.strings = new StringList(new ArrayList<>());

    }

  }

 

Then, when you view the ‘strings’ field in an instance of MyClass, the debugger will show you the full array. You will need to use the ‘...’ to view it and you can even cut and paste it into notepad if want to take a snapshot or view it in a larger window.

 

John

 

From: Admin @ Goodun
Sent: 09 January 2024 12:02
To: users@netbeans.apache.org
Subject: Variable display in debugger

 

Can I get a view of an entire array while debugging php?

 

I have an array of arrays, which means I have to drill down into each

sub-array to actually see data.  This is a problem in my large array

(it has over 200 sub-arrays).

 

So, is there a way to display, or cause to be displayed, such an array

during execution?  It doesn't have to be *in* the debugger, anywhere I

can see it would be ok.

 

TIA

Mark

 

---------------------------------------------------------------------

To unsubscribe, e-mail: users-unsubscr...@netbeans.apache.org

For additional commands, e-mail: users-h...@netbeans.apache.org

 

For further information about the NetBeans mailing lists, visit:

https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

 

 

--------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@netbeans.apache.org For additional commands, e-mail: users-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to