1

I have question regarding some existing working code that looks something like this:

@Autowired
ThreadPoolTaskExecutor executor; 

Future<T> someMethod (Supplier<T> supplier){
  Future<T> future = executor.submit(supplier::get); 
}

I checked the submit() method for ThreadPoolTaskExecutor class, the signature like this:

Future<T> submit(Callable<T> task) 

But in the code instead of passing in a callable, it is passing in the get() method. Why is it accepted? are methods that return results callables? I googled this but didn't find any results.

Could someone explain? Thanks.

Cleo
  • 43
  • 4
  • `supplier::get` is akin to `() -> supplier.get()` is akin to `() -> { return supplier.get(); }`, which can match the method signature for `Callable#call` – Rogue Dec 08 '21 at 17:06
  • No, it has to do with [functional interfaces](https://stackoverflow.com/questions/36881826/what-are-functional-interfaces-used-for-in-java-8). In this case, method reference to a no-arg method returning a value can act as a `Callable`. – Kayaman Dec 08 '21 at 17:37

0 Answers0