Вопрос

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?

Это было полезно?

Решение

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(); 
     }
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top