Is there an interface similar to Callable but with arguments?

后端 未结 8 1585
小蘑菇
小蘑菇 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:14

    Since Java 8 there is a whole set of Function-like interfaces in the java.util.function package. The one you're asking for specifically is simply Function.

    Prior to Java 8, there was no general-purpose, built-in interface for this, but some libraries provided it.

    For example Guava has the Function interface with the method T apply(F input). It also makes heavy use of that interface in several places.

提交回复
热议问题