安卓Runnable接口解释

本人才疏学浅,如有错误之处,还请见谅

Runnable接口解释

官方地址如下:

https://developer.android.google.cn/reference/java/lang/Runnable?hl=en

官方解释如下

The Runnable interface should be implemented by any class whose instances are intended to be executed by a thread. The class must define a method of no arguments called run.

This interface is designed to provide a common protocol for objects that wish to execute code while they are active. For example, Runnable is implemented by class Thread. Being active simply means that a thread has been started and has not yet been stopped.

In addition, Runnable provides the means for a class to be active while not subclassing Thread. A class that implements Runnable can run without subclassing Thread by instantiating a Thread instance and passing itself in as the target. In most cases, the Runnable interface should be used if you are only planning to override the run() method and no other Thread methods. This is important because classes should not be subclassed unless the programmer intends on modifying or enhancing the fundamental behavior of the class.

慢慢的翻译下

这个Runnable 接口应该被那些有意实现单线程的例子继承

这个例子必须定义一个没有参数的方法run

这个接口设计出来为对象提供了一个一般的协议来执行活跃的代码(抱歉这段话我没有理解出来到底是什么意思) 举一个例子 Thread 继承了 Runnable后,Thread就是一个活的单线程例子.

而且,Runnable提供了方法对一个类来成为活进程。而且没有子类化 Thread,一个类继承了Runnable可以运行而且不被子类化。Thread就是一个例证

实例并将自身作为目标传入。在大多数请胯下,Runnable接口应该被使用,如果你只是计划去重写一下run() 方法 并不写Thread方法,这是重要的,因为类不应该被子类化。除非这个项目打算修饰或者加强 基本原则 表现关于这个类。

下面是关于run方法的翻译

public abstract void run ()

When an object implementing interface Runnable is used to create a thread, starting the thread causes the object‘s run method to be called in that separately executing thread.

The general contract of the method run is that it may take any action whatsoever.

翻译:

当一个类实现了Runnable接口时,Run方法就需要重写了。

Run方法是为了在一个单独分开的单线程里面生成的一个方法.

方法运行的一般约定是它可以采取任何操作。

安卓Runnable接口解释

上一篇:股票投资相关,移动平均线


下一篇:10 部署应用程序和applet