Log.d(TAG, "onChanged: " + loggedUserAuthResource.data.getUserPhotos());List<UserPhoto> copiedList = loggedUserAuthResource.data.getUserPhotos();copiedList.add(new UserPhoto("ADD"));Log.d(TAG, "onChanged: " + copiedList);Log.d(TAG, "onChanged: " + loggedUserAuthResource.data.getUserPhotos());如您所見,我只想將一個項目添加到我復制的列表中,但它也會添加到 loggedUserAuthResource 列表中。2019-08-18 15:06:18.104 8151-8151/ D/EditProfileActivity: onChanged: [UserPhoto{photoName='110ab4146695a093834701640fcee83c_y.jpg', orderId=1}, UserPhoto{photoName='59b7ee6ad3107d83227d017c45ffc899_y.jpg', orderId=2}, UserPhoto{photoName='90ae37db9a5d44026ebad8f622bf2c59_y.jpg', orderId=3}, UserPhoto{photoName='d2f7968640ebb4260b5e5dd1a10c1efd_y.jpg', orderId=4}, UserPhoto{photoName='e792f85d4f53a777f4399fe79f8edd99_y.jpg', orderId=5}, UserPhoto{photoName='22f943f0507223ce31fa1ca3c0e61b32_y.jpg', orderId=6}, UserPhoto{photoName='8b19b52c1482c522be21151eb4eb8009_y.jpg', orderId=7}]2019-08-18 15:06:18.104 8151-8151/ D/EditProfileActivity: onChanged: [UserPhoto{photoName='110ab4146695a093834701640fcee83c_y.jpg', orderId=1}, UserPhoto{photoName='59b7ee6ad3107d83227d017c45ffc899_y.jpg', orderId=2}, UserPhoto{photoName='90ae37db9a5d44026ebad8f622bf2c59_y.jpg', orderId=3}, UserPhoto{photoName='d2f7968640ebb4260b5e5dd1a10c1efd_y.jpg', orderId=4}, UserPhoto{photoName='e792f85d4f53a777f4399fe79f8edd99_y.jpg', orderId=5}, UserPhoto{photoName='22f943f0507223ce31fa1ca3c0e61b32_y.jpg', orderId=6}, UserPhoto{photoName='8b19b52c1482c522be21151eb4eb8009_y.jpg', orderId=7}, UserPhoto{photoName='ADD', orderId=0}]為什么會這樣?我怎么能阻止它?
Java 復制 ArrayList 值不是引用
慕蓋茨4494581
2023-06-08 19:44:49