Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
327 views
in Technique[技术] by (71.8m points)

java - 如何使用IntelliJ快捷方式将Java中的Runnable更改为lambda表达式(How to change Runnable to lambda expression in Java with IntelliJ shortcut)

I have the following anonymous Runnable implementation.

(我有以下匿名Runnable实现。)

Runnable cronTask = new Runnable() {
       @Override
       public void run() {
          // do something
       }
};

IntelliJ suggests that I replace it with a lambda expression.

(IntelliJ建议我将其替换为lambda表达式。)

eg:

(例如:)

Runnable cronTask = () -> {
     // multiple "do something" statements
};

When using a single statement the syntax is:

(使用单个语句时,语法为:)

Runnable cronTask = () -> doSomething();

What shortcut can I use to convert it?

(我可以使用什么快捷方式进行转换?)

  ask by Technotronic translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Let IntelliJ do the lifting here;

(让IntelliJ在这里完成工作;)

you can invoke Alt + Enter (or Option + Return on Mac) to allow IntelliJ to replace it with a lambda expression.

(您可以调用Alt + Enter (或在Mac上为Option + Return )以允许IntelliJ用lambda表达式替换它。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...