Monday, 26 August 2013

Java - How to create "anonymous" class on the fly

Java - How to create "anonymous" class on the fly

I can do this:
new Object(){
public void hi(){}
}.hi();
how do i (or can i) do this:
IDontWorkForSomeReasonThread t = new IDontWorkForSomeReasonThread extends
Thread(){
public void NoNoYouCantCallMe(String s){}
};
t.NoNoYouCantCallMe("some useful data that i will need later, but don't
want to save this anonymous class");

No comments:

Post a Comment