Java复制clone工具类

2021-10-18 16:27:08 浏览数 (1)

代码语言:javascript复制
public static <T> T clone(T object) {
    if (object instanceof Collection) {
        Collection co = (Collection) object;
        return (T) clone(co);
    } else if (object instanceof Map) {
        Map map = (Map) object;
        return (T) clone(map);
    } else {
        String s = JSON.toJSONString(object);
        return (T) JSON.parseObject(s, object.getClass());
    }
}

0 人点赞