Java 代码评估(IntelliJ IDE),在某些时候使用 toString() 吗? [英] Java code evaluation (IntelliJ IDE), use toString() in some point?
问题描述
评估对象初始化时,出现toString nullPointerException.
When evaluating object initialization, toString nullPointerException appear.
方法抛出java.lang.NullPointerException"异常.无法评估 XXXX.toString()
Method threw 'java.lang.NullPointerException' exception. Cannot evaluate XXXX.toString()
重现此问题的代码示例:
Code example which recreates this issue:
Car car = carUtils.objectMapper.readValue(new File(pathTo("carProperties.json")), Car.class);
为什么会这样?评估是否使用 toSting() 调用完成?
Why is that happens? is the evaluation done using toSting() invocations?
推荐答案
我发现了这种行为的根本原因.
I have discovered the root cause for this behavior.
您可以选择 IntelliJ 评估以何种方式显示数据:结果可以是 Object 或 toString 评估.因此,我遇到了错误,使用了 View as->toString,而并非所有对象都实现了 toString.希望它会在未来对某人有所帮助.
You can choose in what way IntelliJ evaluation will display the data: the result can be the Object or toString evaluation. Therefore the error i had experienced, View as->toString was used, while not all the objects had toString implemented. Hope it will help someone in the future.
您可以通过右键单击变量(在调试器的变量窗口内)并单击查看为"来更新变量的显示类型
You can update the display type for a variable by right clicking on the variable (inside the variables window of the debugger) and clicking on 'View as'
如果不想每次都手动更新,可以在 IntelliJ 属性中更改 遵循以下步骤
If you don't want to update it manually each time, you can change it in IntelliJ properties following this steps
这篇关于Java 代码评估(IntelliJ IDE),在某些时候使用 toString() 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!