Two methods about anonymous inner class implementation

Both methods are commonly used.

The first method
Timer time= new Timer();
time.schedule(new TimerTask() {

         @Override
         public void run() {
             // TODO Auto-generated method stub

         }

     },100,100);

     //TimerTask 因为继承了抽象类或接口,匿名内部类没有构造方法,抽象类不能直接定义对象。
    ** 第二种方法**
     TimerTask tt= new TimerTask() {  //匿名内部类

         @Override
         public void run() {
             // TODO Auto-generated method stub

         }
     }
     time.schedule(tt, 1000);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324479304&siteId=291194637