Java how to print all local variables?

后端 未结 6 2001
长情又很酷
长情又很酷 2021-01-12 04:25

I have a method and want to examine variables inside it without debugging - is it possible in Java?

I do not want to write tons of code like:

Syste         


        
6条回答
  •  悲&欢浪女
    2021-01-12 04:49

    I want to have something like: System.out.printLocals();

    Also it should be great to have something like: System.out.printMembersOf(someObjectInstance);

    Just about every Java class has a toString method. You override that method, and you can get a string that represents what you're asking for.

    Eclipse Helios, among other IDEs, will generate a basic toString method for you.

提交回复
热议问题