Java Array Comparison

前端 未结 6 1845
名媛妹妹
名媛妹妹 2021-01-04 19:48

Working within Java, let\'s say I have two objects that, thanks to obj.getClass().isArray(), I know are both arrays. Let\'s further say that I want to compare

6条回答
  •  伪装坚强ぢ
    2021-01-04 20:27

    I'm afraid the only alternative would be to use reflection, which would be nearly as ugly.

    Arrays.getClass()
          .getMethod("equals", new Class[]{obj1.getClass(), obj2.getClass()})
          .invoke(null, new object[]{obj1, obj2});
    

    Not tested, could fail in all kinds of ways, needs lots of exception handling...

提交回复
热议问题