Java 代码评估(IntelliJ IDE),在某些时候使用 toString() 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20950377/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java code evaluation (IntelliJ IDE), use toString() in some point?
提问by Johnny
When evaluating object initialization, toString nullPointerException appear.
在评估对象初始化时,出现 toString nullPointerException。
Method threw 'java.lang.NullPointerException' exception. Cannot evaluate XXXX.toString()
方法抛出“java.lang.NullPointerException”异常。无法评估 XXXX.toString()
Code example which recreates this issue:
重现此问题的代码示例:
Car car = carUtils.objectMapper.readValue(new File(pathTo("carProperties.json")), Car.class);
Why is that happens? is the evaluation done using toSting() invocations?
为什么会这样?评估是使用 toSting() 调用完成的吗?
采纳答案by Johnny
I have discovered the root cause for this behavior.
我已经发现了这种行为的根本原因。
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.
您可以选择 IntelliJ 评估以何种方式显示数据:结果可以是Object 或 toString 评估。因此,我遇到了错误,使用了 View as->toString,而并非所有对象都实现了 toString。希望它会在将来对某人有所帮助。
If you don't want to update it manually each time, you can change it in IntelliJ properties following this steps
如果您不想每次都手动更新它,您可以按照以下步骤在 IntelliJ 属性中更改它