Can someone provide me with a good simple example of a regular nested class and then the same class re-written as an anonymous inner class?
Asked
Active
Viewed 1,476 times
-4
-
1You can get your IDE to do this. Create an anonymous inner class and when get your IDE to move the class and refactor it for you. – Peter Lawrey Oct 16 '13 at 23:36
-
1stack overflow has lots of answer regarding this i think – Sage Oct 16 '13 at 23:38
1 Answers
1
Here are examples:
public class Outer {
public static class NestedStatic implements Runnable {
public void run(){
doSomething();
}
public static void main(String[] args){
Thread nestThread=new Thread(new NestedStatic());
nestThread.start();
// now anonymous:
Thread anonThread=new Thread(new Runnable(){
public void run(){
doSomethingElse();
});
anonThread.start();
}
}

nanofarad
- 40,330
- 4
- 86
- 117