Is there an interface similar to Callable but with arguments?

后端 未结 8 1691
小蘑菇
小蘑菇 2021-01-31 02:03

Is there an interface in Java similar to the Callable interface, that can accept an argument to its call method?

Like so:

public interface M         


        
8条回答
  •  爱一瞬间的悲伤
    2021-01-31 02:19

    The answer is ambiguous. Strictly speaking, that is, "for the same purpose of the Callable interface", there is not.

    There are similar classes, and depending on what you want, they may or may not be convenient. One of them is the SwingWorker. However, as the name implies, it was designed for use within the Swing framework. It could be used for other purposes, but this would be a poor design choice.

    My best advice is to use one provided by an extension library (Jakarta-Commons, Guava, and so on), depending on what libraries you already use in your system.

提交回复
热议问题