我正在用Java创建一个项目,并通过另一个类函数传递一个对象。该对象包含一个对象的链接列表。如果我在另一个类中删除其中一个对象,它只会删除它的副本,还是会通过引用传递?
这是我的删除类的示例,它包含根文件夹,名称,并从链接列表中包含的子文件夹中删除名称。
public class Delete {
public static void delete_(String name, folder root)
{
for (folder s : root.folderlist) {
delete_i(name, s);
}
}
public static void delete_i(String name, folder check)
{
if(check.name.equals(name))
{
int count = 0;
System.out.println("Found folder! Deleting...");
for(folder s : check.parent.folderlist)
{
if(s.name.contains(name))
{
System.out.println("Found Parent folder of " + s.name + " which is " + s.parent.name + " Deleting from list...");
check.parent.folderlist.remove(count);
System.out.println("Folder successfully removed!");
break;
}
count += 1;
}
}
for (folder l : check.folderlist) {
delete_i(name, l);
}
}
}
答案 0 :(得分:2)
它将更改对象并从中删除。