Skip to content

Instantly share code, notes, and snippets.

@cscotta
Created November 23, 2010 07:42
Show Gist options
  • Select an option

  • Save cscotta/711414 to your computer and use it in GitHub Desktop.

Select an option

Save cscotta/711414 to your computer and use it in GitHub Desktop.
import java.util.Timer;
import java.util.TimerTask;
import java.lang.reflect.Method;
public class Abomination {
String callback;
public static void main(String args[]) {
new Abomination().setInterval("lol", 1000);
}
void setInterval(String callback, long interval) {
this.callback = callback;
new Timer().scheduleAtFixedRate(setInterval, 0, 1000);
}
public void lol() {
System.out.println("lol");
}
TimerTask setInterval = new TimerTask() {
public void run() {
try {
Method method = Abomination.this.getClass().getMethod(callback, new Class[]{});
method.invoke(Abomination.this.getClass().newInstance(), new Object[]{});
} catch (Exception e) { e.printStackTrace(); }
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment