代码改变世界

[hyddd的FindBugs分析记录][H C EC] equals() used to compare array and nonarray

2009-04-01 20:11  hyddd  阅读(782)  评论(0编辑  收藏  举报

[H C EC] equals() used to compare array and nonarray [EC_ARRAY_AND_NONARRAY]

This method invokes the .equals(Object o) to compare an array and a reference that doesn't seem to be an array. If things being compared are of different types, they are guaranteed to be unequal and the comparison is almost certainly an error. Even if they are both arrays, the equals method on arrays only determines of the two arrays are the same object. To compare the contents of the arrays, use java.util.Arrays.equals(Object[], Object[]). 

 

先看下面一段代码:

String[] strs = {"1"};
//.
If("1".equals(strs)){
//todo
}

上面这段代码,if里面的代码是永远都不会被执行的,因为我们用了一个非数据(nonarray)和一个数组(array)做equals(),这里估计是写代码时的笔误。