Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 通过匿名类使用线程时隐式转换到可运行接口?_Java_Android_Multithreading_Casting - Fatal编程技术网

Java 通过匿名类使用线程时隐式转换到可运行接口?

Java 通过匿名类使用线程时隐式转换到可运行接口?,java,android,multithreading,casting,Java,Android,Multithreading,Casting,当我使用thread类的这个构造函数:thread(Runnable target)并在构造函数中使用匿名类时,我们能说隐式转换发生了吗?在隐式转换中,匿名类的对象被转换为Runnable接口?否 每个匿名类都有基类或接口,并且该类或接口必须扩展Runnable,这样就不需要隐式或显式强制转换 但如果您的基类没有扩展可运行,则会发生编译错误: new Thread(new Object(){}); new Thread(new Serializable(){});

当我使用thread类的这个构造函数:thread(Runnable target)并在构造函数中使用匿名类时,我们能说隐式转换发生了吗?在隐式转换中,匿名类的对象被转换为Runnable接口?

每个匿名类都有基类或接口,并且该类或接口必须扩展
Runnable
,这样就不需要隐式或显式强制转换

但如果您的基类没有扩展
可运行
,则会发生编译错误:

    new Thread(new Object(){});
    new Thread(new Serializable(){});