English 中文(简体)
班级本身是否可取消。
原标题:Can a class be nullified from within the class itself?

例如,该法典是否有效?

class abc{
    int x,y;
    abc(int x,int y){
        this.x=x;
        this.y=y;
        while(true)
            update();
    }

    public void update(){
        x--;
        y--;
        if(y==0)
            this=null;
    }
 }

如果上述情况无效,请解释原因。 我需要一个等级,即经过某些改动后不再存在。 请建议采用上述办法。

最佳回答

页: 1 理由是,你不提出反对。 当你说<代码>obj = 无; 您仅将<代码>null 列入以前提到物体的变量。 可能还有许多其他提及同一物体之处。

我认为,你想要做的是,是哪类无效物品,并把它当作垃圾收集起来,而是在该类别内作出这一决定。 如果是问题,我就建议你研究一些薄弱环节。

其他可能的解决办法是,在java实施“智能参考”。 您可创建<代码>SmartReference,真正提及该物体。 该物体应背书这一智能参考书,并称其方法invalidate() ,如你故意错误的表述this = 无。 你们必须小心,不要直接提及这些物体,而只是通过智能提及。

唯一的问题是“你想要做吗? 事实上,这将导致该法典更加复杂和不稳定。 Imagine:该物体决定自己无效,因此,“智能参考”一词的意思是<代码>null。 现在,这一聪明参考资料的所有持有人在试图使用该物体时都会得到国家人民党的承认! 这正是这种机制在java不存在的原因,而申请方案者不能直接保留记忆。

底线:删除所有物体,让GC从事辛勤工作。 信托。 它知道清理垃圾。

问题回答

无,该法典无效。

Furthermore, I don t see what meaningful semantics it could have had if it were valid.

请建议采用上述办法。

只要提到该物体,该物体就存在。 为了使该物体符合收集垃圾的资格,你只需要确保不提及该物品(就你而言,只要<代码>y到达零时,就应当如此。

I think this is a good question. I ve had loads of cases where I d like Objects to validate themselves after/during construction and if it finds reason to, to just return an empty value or go back up the stack and skip over creating that object.

最重要的是,如果你正在从其他价值清单中编制一份物体清单。 如果价值是垃圾,你想要承认这一点。

那么,为了验证创作,就必须在班级之外规定一种功能,而允许该物体这样做是完全的。

这是一种可耻的 j,它假定方案执行者可能去掉。 如果你说得好的话,那就是一个 n。

I think you need to rethink why you want to do this, because what you re suggesting doesn t even exist as a concept in Java.

<代码>该变量总是指标本身。 页: 1 (自此以后,你重新做的是提及<代码>null而不是其先前物体。) 用this来做,因为always<>/em>是目前物体的参照点。

你们是否试图强迫某个物体被销毁/收集垃圾? 如果是的话,你可以不这样做,尽管你的法典的其他部分仍然提到它(如果它们没有提及的话,则会收集垃圾)。

What did you hope/think this would do, anyway?

your code must be get compile time error.. Coz..

The left-hand side of an assignment must be a variable

http://www.un.org。

this=null;




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...