php – Is there any Java function equivalent to var_dump()?

Question:

Does anyone know if there is any Java function equivalent to var_dump() ?

Answer:

There is no equivalent in java, but I found a solution that can be useful to you in SOen ( Link ), I will translate it below:

Your alternatives are to override the object's toString() method to output its contents in a way that suits you, or use reflection to inspect the object (similar to what debuggers do).

The advantage of using reflection is that you don't need to modify your individual objects to be "parsable", however it adds complexity and if you need to support a nested object you will have to write that.

Field[] fields = o.getClass().getDeclaredFields();
for (int i=0; i<fields.length; i++)
{
    System.out.println(fields[i].getName() + " - " + fields[i].get(o));
}
Scroll to Top
AllEscort