是否在Java调试中应用了toString副作用? [英] Do toString side effects get applied in java debugging?

查看:48
本文介绍了是否在Java调试中应用了toString副作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Eclipse中调试Java代码时,如果单击变量名之一,则将打印该对象.对象的toString()方法用于打印它.如果某些toString方法有副作用,而我单击该类型的变量,是否会应用其toString的副作用(并且毫无疑问会弄乱一切)?

When debuggind java code in eclipse, if you click on one of the variable names, that object gets printed. The object's toString() method is used to print it. If some toString method has a side effect and I click on a variable of that type, will the side effects of its toString get applied (and doubtlessly mess everything up)?

推荐答案

我认为您回答了自己的问题.每当您在调试中或以其他方式调用 toString 时,都会发生所有副作用.这就是为什么您应该避免在toString中产生副作用的原因.

I think you answered your own question. Any time you call toString, in debugging or otherwise, all side effects will occur. This is exactly why you should avoid side effects in toString.

这篇关于是否在Java调试中应用了toString副作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆