System.out.println() 总是显示 class 而不是值

System.out.println() always display class not value

如何在Java中显示对象内容的值?我总是得到类似的东西:org.springframework.ws.soap.security.xwss.XwsSecurityInterceptor@1a28aef12019-10-13

@Bean
    public XwsSecurityInterceptor securityInterceptor() {
        XwsSecurityInterceptor securityInterceptor = new XwsSecurityInterceptor();
        securityInterceptor.setPolicyConfiguration(new ClassPathResource("securityPolicy.xml"));
        securityInterceptor.setCallbackHandler(callback());
        System.out.print("toStringBean: "+securityInterceptor.toString());


        //Security Policy -> securityPolicy.xml
        return securityInterceptor;
    }

我读到我应该使用 toString() 但我得到了相同的结果。我只需要对象内部的属性值 :)

您无法使用 toString 方法读取 XwsSecurityInterceptor 的属性,因为它在 class 中未被对象 class.If 覆盖 您想要查看值最好将调试点放在 class 并在调试模式下检查值和 运行 应用程序。 对于 intellij 中的调试。

单击下面屏幕截图中的错误按钮。要添加调试点,只需单击行号。然后行号上出现一个红点。当您 运行 申请时。您可以看到执行在该点停止。然后右键单击变量和 select Evaluate Expression 并打开一个弹出窗口。只需单击弹出窗口中的评估按钮,您就可以看到 class.

中存在的对象的不同值