Java 什么是“内联线程”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2000218/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 02:18:56  来源:igfitidea点击:

What is "inline thread"?

javamultithreading

提问by karthick prabhu

What does "inline thread" mean?

“内联线程”是什么意思?

I got this question during my latest interview. Anybody used this?

我在最近的一次采访中遇到了这个问题。有人用过这个吗?

回答by danben

I believe it refers to the practice of creating an anonymous class extending Thread and calling its start method in the same line of code.

我相信它指的是创建一个匿名类扩展 Thread 并在同一行代码中调用其 start 方法的做法。

(new Thread() {
  public void run() {
    // do stuff
  }
 }).start();

As stated elsewhere, this is not an "official" Java term. But I think it's still good to know how concepts might be referred to differently, if only for the sake of communication.

如别处所述,这不是“官方”Java 术语。但我认为了解如何以不同方式引用概念仍然很好,即使只是为了交流。

回答by Pace

It's really just another name for an anonymous thead.

它实际上只是一个匿名tad的另一个名字。

( new Thread() { public void run() { 
// do something 
} } ).start(); 

回答by Michael Borgwardt

"inline thread" is not an established term in Java. It was a bad question.

“内联线程”在 Java 中不是一个既定的术语。这是一个糟糕的问题。

Some people seem to use the term to mean threads defined using anonymous classes, as shown in the other answers. But again, this is not official or even widespread usage, and not something by which you could usefully measure someone's Java knowledge.

有些人似乎使用该术语来表示使用匿名类定义的线程,如其他答案所示。但同样,这不是官方的,甚至不是广泛使用的,也不是您可以有用地衡量某人的 Java 知识的东西。

回答by Ascalonian

I am guessing this means creating a thread sorta like...

我猜这意味着创建一个线程有点像......

new Thread(
  new Runnable() {

      public void run() {
         ...
      }
}).start();