androidrunnable使用_安卓Runnable接口解释

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

Runnable接口解释

官方地址如下:

官方解释如下

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方法是为了在一个单独分开的单线程里面生成的一个方法.

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值