1、导入的maven依赖包
commons-beanutils
commons-beanutils
1.9.4
2、示例代码
package cn.ljxwtl.设计模式.原型模式;
import cn.ljxwtl.设计模式.原型模式.entity.DeepPersonWithInputStream;
import com.sun.xml.internal.messaging.saaj.util.ByteInputStream;
import org.apache.commons.beanutils.BeanUtils;
import java.lang.reflect.InvocationTargetException;
public class BeanUtilsTest {
public static void main(String[] args) throws InvocationTargetException, IllegalAccessException {
DeepPersonWithInputStream deepPersonWithInputStream = new DeepPersonWithInputStream("王小明", 30, Boolean.TRUE, "北京市昌平区", new ByteInputStream());
DeepPersonWithInputStream deepPersonWithInputStreamCopy = new DeepPersonWithInputStream();
BeanUtils.copyProperties(deepPersonWithInputStreamCopy,deepPersonWithInputStream);
System.out.println(deepPersonWithInputStream.hashCode());
System.out.println(deepPersonWithInputStreamCopy.hashCode());
System.out.println("---------------------------------");
System.out.println(deepPersonWithInputStream);
System.out.println(deepPersonWithInputStreamCopy);
System.out.println(deepPersonWithInputStream.getInputStream().hashCode());
System.out.println(deepPersonWithInputStreamCopy.getInputStream().hashCode());
}
}