How to use TimerTask with lambdas?

后端 未结 5 1723
逝去的感伤
逝去的感伤 2020-12-05 14:29

As you hopefully know you can use lambdas in Java 8, for example to replace anonymous methods.

An example can be seen here of Java 7 vs Java 8:

Runna         


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-05 15:02

    You can also create a Timer easily with lambdas from the Swing API if you want (but not with TimerTask) :

    new javax.swing.Timer(1000, (ae) -> this::checkDirectory).start();

提交回复
热议问题