What is the Java equivalent of PHP var_dump?

后端 未结 11 634
北荒
北荒 2020-12-12 14:58

PHP has a var_dump() function which outputs the internal contents of an object, showing an object\'s type and content.

For example:

         


        
11条回答
  •  孤城傲影
    2020-12-12 15:13

    I like to use GSON because it's often already a dependency of the type of projects I'm working on:

    public static String getDump(Object o) {
        return new GsonBuilder().setPrettyPrinting().create().toJson(o);
    }
    

    Or substitute GSON for any other JSON library you use.

提交回复
热议问题