Skip to content

Instantly share code, notes, and snippets.

@arnaudbreton
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnaudbreton/9004764 to your computer and use it in GitHub Desktop.
Save arnaudbreton/9004764 to your computer and use it in GitHub Desktop.
Java and destructor
public class Global {
public static Temporary[] a;
public static void main(String [] args) throws Throwable
{
new Temporary().finalize();
System.out.println(Global.a[0].toString());
}
}
class Temporary
{
public Temporary ref;
public Temporary() {
this.ref = this;
}
protected void finalize() throws Throwable {
try {
if(Global.a == null) {
Global.a = new Temporary[1];
}
else {
Temporary[] a = new Temporary[Global.a.length+1];
for(int i=0;i<Global.a.length;i++) {
a[i] = Global.a[i];
}
Global.a = a;
}
Global.a[Global.a.length-1] = this;
} finally {
super.finalize();
}
}
}
Temporary@5552e7a4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment