当前位置:网站首页>Deep Copy
Deep Copy
2022-06-22 02:40:00 【Cloud returns - Dusk】
import java.lang.reflect.*;
import java.util.*;
public class DeepCopy {
@SuppressWarnings("unchecked")
public static <T> T copy(T b) {
try {
if (b instanceof String || b instanceof Character || b instanceof Number || b instanceof Boolean)
return b;
T a = (T) b.getClass().getConstructor().newInstance();
for (Field f : getAllFields(b))
f.set(a, copy(f.get(b)));
return a;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
static List<Field> getAllFields(Object o) {
List<Field> list = new ArrayList<>();
Class<?> clazz = o.getClass();
for (; clazz != Object.class; clazz = clazz.getSuperclass()) {
try {
list.addAll(Arrays.asList(clazz.getDeclaredFields()));
} catch (Exception e) {
e.printStackTrace();
}
}
return list;
}
}
边栏推荐
- Minecraft 1.18.2 生化8 模组 1.3版本 物品3D化+更加复杂村庄
- Brief introduction to common pigtails of communication pigtails
- June25,2022 PMP Exam clearance manual-3
- 目标检测之——labelImg标注工具使用方法
- EMC Radiation Emission rectification - principle Case Analysis
- A short video costs hundreds of thousands of yuan, and the virtual digital man makes a circle with "strength"
- 【7. 高精度除法】
- rt_ Message queue of thread
- C mapster object mapper learning
- What is a neural network
猜你喜欢

Ioerror: no translation files found for default language zh cn Solutions for

Get to know unity3d (project structure, third-party plug-in of probuilder)

A short video costs hundreds of thousands of yuan, and the virtual digital man makes a circle with "strength"

Wechat applet film and television review and exchange platform system graduation design completion (7) Interim inspection report

MATLAB 学习笔记(5)MATLAB 数据的导入和导出

【7. 高精度除法】

Wechat applet film and television review and exchange platform system graduation design (1) development outline

Fabric. JS iText set italics manually

Neo4j 技能树正式发布,助你轻松掌握Neo4j图数据库

MySQL 递归查找树形结构,这个方法太实用了!
随机推荐
【8、一维前缀和】
目标检测之——labelImg标注工具使用方法
Graphacademy course explanation: introduction to neo4j graph data science
Technical exploration: 360 digital subjects won the first place in the world in ICDAR OCR competition
Idea ---- copy and paste
Using OKR for HR digital transformation
Live broadcast on June 22 | zhanzhihui, South China Institute of Technology: evolutionary computing for expensive optimization
使用 OKR 进行 HR 数字化转型
Introduction to excellent verilog/fpga open source project (XXVII) - small CPU
Word document to markdown document?
使用 OKR 進行 HR 數字化轉型
June25,2022 PMP Exam clearance manual-5
EMC整改小技巧
Which Amazon evaluation system is better?
idea----bookmark
最新发布:Neo4j 图数据科学 GDS 2.0 和 AuraDS GA
OpenJudge NOI 1.13 46:八进制到十进制
Linxu modify the permissions of the folder so that everyone can access 777
Brief analysis of application source code of neo4j intelligent supply chain
华阳智能冲刺深交所:拟募资4亿 复星惟盈是股东