Callable vs Supplier interface in java

前端 未结 3 1343
春和景丽
春和景丽 2021-02-19 16:35

The Callable and Supplier functional interfaces in java.util.concurrent and java.util.function packages respectively have the

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-19 17:31

    Apart from the obvious, Callable throwing an exception, the difference is semantic. They have different names because they represent different things. The purpose is to make code easier to understand. When you use a Callable, your interface choice implies that the object is going to be executed by another thread. When you use Supplier you imply that it's just an object that supplies data to another component.

提交回复
热议问题