public static void main(String[] args) throws CloneNotSupportedException {
final List<Subscribe> zpResultAdsList = Lists.newArrayList();
Subscribe zpResultAds = new Subscribe();
zpResultAds.setUserId("123456");
zpResultAds.setBid("6000.0");
zpResultAdsList.add(zpResultAds);
final Subscribe clone = zpResultAds.clone();
System.out.println("========对象深拷贝===地址==========");
System.out.println(zpResultAds.hashCode());
System.out.println(clone.hashCode());
final List<Object> objects = Lists.newArrayList(10);
final List<Object> objects3 = Arrays.asList(new Object[10]);
System.out.println("=====测试List初始化方式=====");
System.out.println(objects.size());
System.out.println(objects3.size());
List dest = Arrays.asList(new Object[zpResultAdsList.size()]);
Collections.copy(dest, zpResultAdsList);
System.out.println("Collections.copy========List 对象地址==========");
System.out.println(zpResultAdsList.hashCode());
System.out.println(dest.hashCode());
List<String> stringsSrc = Lists.newArrayList("12", "13", "14");
List<String> stringsTarget = Arrays.asList(new String[10]);
Collections.copy(stringsTarget, stringsSrc);
System.out.println("Collections.copy========List String地址==========");
System.out.println(stringsSrc.hashCode());
System.out.println(stringsSrc.hashCode());
final Object[] objects1 = zpResultAdsList.toArray();
final Object[] objects2 = new Object[objects1.length];
System.arraycopy(objects1, 0, objects2, 0, zpResultAdsList.size());
System.out.println("System.arraycopy========数组地址==========");
System.out.println(objects1.hashCode());
System.out.println(objects2.hashCode());
final Cloner cloner = new Cloner();
final List<Subscribe> zpResultAds1 = cloner.deepClone(zpResultAdsList);
System.out.println(zpResultAdsList.hashCode());
System.out.println(zpResultAds1.hashCode());
}
@Data
public class Subscribe implements Cloneable {
private String bid;
private String userId;
@Override
public Subscribe clone() throws CloneNotSupportedException {
Subscribe zpResultAds = null;
try {
zpResultAds = (Subscribe) super.clone();
} catch (Exception e) {
System.out.println("对象深拷贝异常" + e);
}
return zpResultAds;
}
}
|