Skip to main content

Runnable

Trait Runnable 

Source
pub trait Runnable:
    JObjRef
    + JObjNew
    + PartialEq
    + Debug {
    const CLASS: &'static str = "java/lang/Runnable";
    const OBJECT_SIG: &'static str = "Ljava/lang/Runnable;";
    const DIM: u8 = 0;

    // Required method
    fn run(&self);
}
Expand description

任何实例旨在由线程执行的类都应实现 Runnable 接口。该类必须定义一个名为 run 的无参数方法。此接口旨在为希望在活动期间执行代码的对象提供通用协议。例如,Runnable 由 Thread 类实现。 活动状态仅表示线程已启动且尚未停止。此外,Runnable 还提供了在不子类化 Thread 的情况下使类处于活动状态的方法。实现 Runnable 的类可以通过实例化 Thread 实例并将其自身作为目标传递,而无需子类化 Thread 即可运行。 在大多数情况下,如果您只打算覆盖 run() 方法而不覆盖其他 Thread 方法,则应使用 Runnable 接口。这一点很重要,因为除非程序员打算修改或增强类的基本行为,否则不应子类化类。

Provided Associated Constants§

Source

const CLASS: &'static str = "java/lang/Runnable"

java/lang/Runnable

Source

const OBJECT_SIG: &'static str = "Ljava/lang/Runnable;"

Ljava/lang/Runnable;

Source

const DIM: u8 = 0

数组维度

Required Methods§

Source

fn run(&self)

当使用实现 Runnable 接口的对象创建线程时,启动该线程会导致在该单独执行的线程中调用该对象的 run 方法。 方法 run 的一般约定是它可以采取任何操作。

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§