简体   繁体   中英

Java threads. Runnable interface

I want to clarify a doubt in multi threading in java. Cant we create an interface with run() and implement it instead of Runnable interface. Will it work?

No it won't work.

Or at least, it won't work unless your interface implements the real Runnable interface.

Java inheritance is NOT based on duck typing. Two unrelated interfaces with the same method signatures are not type compatible in the Java type system.

Reference:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM