Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用Apache反射比较两个对象失败_Android_Object_Compare - Fatal编程技术网

Android 使用Apache反射比较两个对象失败

Android 使用Apache反射比较两个对象失败,android,object,compare,Android,Object,Compare,我有两个完全相同的对象(我知道),换句话说,所有属性都是相同的 Object A Object B 实现Apache反射的类如下所示: public class Base<T> { @Override public boolean equals(Object obj) { try { if (!this.getClass().isInstance(obj)) { return false

我有两个完全相同的对象(我知道),换句话说,所有属性都是相同的

Object A

Object B
实现Apache反射的类如下所示:

public class Base<T> {

    @Override
    public boolean equals(Object obj) {

        try {

            if (!this.getClass().isInstance(obj)) {
                return false;
            }

            if(EqualsBuilder.reflectionEquals(this, obj)){
                return true;
            }

            return false;

        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }    
}
Device info是另一个类似于Device类的类(实际上是一个扩展),但只是有更详细的属性。如前所述,这两个对象是相同的-我手动将每个对象中的每个属性设置为相同的值,并通过分别检查每个属性进行验证

这个方法适用于更简单的对象,但我不明白为什么它在这个更复杂的对象上失败?所谓复杂,我指的是一个类,它有另一个类作为属性。Android内容值似乎不会影响成功/失败

public class Device extends Base<Object> implements Serializable{


    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private int _id = -1;
    private long create_date = 0;
    private long update_date = 0;
    private int other_id = -1;
    private String description = "";
    private int configuration_id = -1;
    private long sync_date = 0;
    private Device_Info device_info = null;

    public int get_id() {
        return _id;
    }

    public void set_id(int _id) {
        this._id = _id;
    }

    public long getCreate_date() {
        return create_date;
    }

    public void setCreate_date(long create_date) {
        this.create_date = create_date;
    }

    public long getUpdate_date() {
        return update_date;
    }

    public void setUpdate_date(long update_date) {
        this.update_date = update_date;
    }

    public int getOther_id() {
        return other_id;
    }

    public void setOther_id(int other_id) {
        this.other_id = other_id;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public int getConfiguration_id() {
        return configuration_id;
    }

    public void setConfiguration_id(int configuration_id) {
        this.configuration_id = configuration_id;
    }

    public void setSync_date(long sync_date) {
        this.sync_date = sync_date;
    }

    public long getSync_date() {
        return sync_date;
    }

    /**
     * 
     * @return
     */
    public ContentValues getContentValues() {

        // define an object to contain the object values
        ContentValues values = new ContentValues();

        try {

            // set the values of each table column.
            if(this.get_id() > 0){
                values.put("_id", this.get_id());   
            }                       
            values.put("create_date", this.getCreate_date());
            values.put("update_date", this.getUpdate_date());           
            values.put("description", this.getDescription());                   
            values.put("other_id", this.getOther_id());
            values.put("configuration_id", this.getConfiguration_id());
            values.put("sync_date", this.getSync_date());

            return values;

        } catch (Exception e) {
            return values;
        }
    }

    public Device_Info getDevice_info() {
        return device_info;
    }

    public void setDevice_info(Device_Info device_info) {
        this.device_info = device_info;
    }
  }