[英]What is the meaning of ()->System.out.println(“done”)?
In Concurrency Interest link, there is a code which is like this:- 在Concurrency Interest链接中,有一个代码如下: -
exec.schedule( ()-> System.out.println("done"),
1, TimeUnit.SECONDS );
What is the meaning of ()-> ? () - >是什么意思?
I checked in eclipse, it does not allow. 我检查了eclipse,它不允许。 But what was the intention of the thread-writer?
但线程编写者的意图是什么?
That is the Java 8 syntax for Lambda Expressions . 这是Lambda Expressions的Java 8语法。
The ScheduledThreadPoolExecutor#exec(..)
method expects a Runnable
argument. ScheduledThreadPoolExecutor#exec(..)
方法需要一个Runnable
参数。 Runnable
is a functional interface because it only contains one abstract
method. Runnable
是一个功能接口,因为它只包含一个abstract
方法。 As such, the compiler can infer that you are defining a new Runnable
instance with the lambda. 因此,编译器可以推断您正在使用lambda定义新的
Runnable
实例。
The parts between ()
are the run()
method's parameters, ie. ()
之间的部分是run()
方法的参数,即。 none. 没有。 The part after the
->
is the body of the method. ->
之后的部分是方法的主体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.