【问题标题】:Invocation of toString on an array - FindBugs在数组上调用 toString - FindBugs
【发布时间】:2011-07-18 04:52:56
【问题描述】:

我的代码出现以下 Findbugs 错误,

Invocation of toString on <<Package Path>>

 The code invokes toString on an array, which will generate a fairly useless
 result such as [C@16f0472. Consider using Arrays.toString to convert the
 array into a readable String that gives the contents of the array.
 See Programming Puzzlers, chapter 3, puzzle 12. 

代码:

logger.info("Adding information"+ Employee.getName()+ " "+
            employeeForm.getQuestionAndAnswers());

请告诉我是什么错误。

【问题讨论】:

  • 请告诉我代码中的错误到底在哪里

标签: arrays tostring findbugs


【解决方案1】:

正如它所说,做

myArray.toString()

会生成一些无用的东西,比如 java.lang.int[]@45345262

你想使用

Arrays.toString(myArray);

【讨论】:

  • 优秀的先生。竖起大拇指!打印对象的“哈希码”仅用于区分相同类型的实例。除此之外,我认为这是一种罪过!
猜你喜欢
  • 2019-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-21
  • 1970-01-01
  • 2016-06-19
相关资源
最近更新 更多