是否可以将类中的类的实例设置为空。例如,我可以做这样的事情吗
int main{
//Create a new test object
Test test = new Test();
//Delete that object. This method should set the object "test" to null,
//thus allowing it to be called by the garbage collector.
test.delete();
}
public class Test{
public delete(){
this = null;
}
}
我已经尝试过了,但它不起作用。使用“this = null”我得到左侧需要是变量的错误。有没有办法实现类似的东西?