杂豆

欢马劈雪     最近更新时间:2020-01-02 10:19:05

418
杂豆
// 来自 n o w j a v a . c o m - 时  代  Java


//package com.nowjava;

import java.beans.BeanInfo;

import java.beans.Introspector;

import java.beans.PropertyDescriptor;


public class Main {


    public static int hashBean(Object bean) {

        if (bean == null)

            return -1;

        int hash = bean.getClass().hashCode();

        // new ToStringCreator(this)

        try {

            BeanInfo bi = Introspector.getBeanInfo(bean.getClass());

            PropertyDescriptor[] pd = bi.getPropertyDescriptors();

            for (int i = 0; i < pd.length; i++) {/* 来自 NowJava.com - 时  代  Java*/

                if (!"class".equals(pd[i].getName())) {

                    Object result = pd[i].getReadMethod().invoke(bean);

                    if (result != null) {

                        hash += result.hashCode();

                        if (i == pd.length - 1)

                            
展开阅读全文