Java NStruct
Posted Googler
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java NStruct相关的知识,希望对你有一定的参考价值。
package org.rx.bean; import org.rx.Lazy; import org.rx.SystemException; import java.io.Serializable; import java.lang.reflect.Field; public abstract class NStruct implements Serializable { static final long serialVersionUID = 42L; private transient Lazy<Field[]> fields = new Lazy<>(() -> this.getClass().getDeclaredFields()); @Override public int hashCode() { StringBuilder hex = new StringBuilder(); for (Field field : fields.getValue()) { field.setAccessible(true); try { Object val = field.get(this); if (val != null) { hex.append(val.hashCode()); } } catch (IllegalAccessException ex) { throw SystemException.wrap(ex); } } return hex.toString().hashCode(); } @Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof NStruct)) { return false; } NStruct struct = (NStruct) obj; return this.hashCode() == struct.hashCode(); } }
以上是关于Java NStruct的主要内容,如果未能解决你的问题,请参考以下文章