As I was going through JDK 7, I found that java.util.concurrent.RunnableFuture<V>
has a run method. I wonder what the significance of duplicating the same run method signature in the interface is when it already extends Runnable
.
package java.util.concurrent;
public interface RunnableFuture<V> extends Runnable, Future<V> {
/**
* Sets this Future to the result of its computation
* unless it has been cancelled.
*/
void run();
}
It's defined in the interface so that they can attach RunnableFuture
-specific JavaDoc to it. There's no technical significance.
There are no docs that provide such explanation. So I am going to provide my opinion.
I dont think it has any major significance. Imagine how the interface world look
public interface RunnableFuture<V> extends Runnable, Future<V> {
}
Though it is perfectly valid it does not clearly indicate its purpose. So in my opinion it is just been provided for easy understanding for run()
method specific to RunnableFuture
interface. So that you know to put your runnable logic by overriding run()
method.
Another point that I can think of is Runnable
is one of the early interfaces and if you see the run() method it is
public abstract void run();
and public
and abstract
keywords are redundant as methods in an interface are by default public
and abstract
. To improvise this might be one of the reasons.
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.