Is there an interface similar to Callable but with arguments?

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

    Normally arguments are not required as the method can have any number of arguments in its constructor.

    final int i = 5;
    final String word = "hello";
    
    Future future = service.submit(new Callable() {
        public String call() {
            return word + i;
        }
    });
    

    In this example i and word have been used, but you can "pass" any number of parameters.

提交回复
热议问题