kirillrakhman
12/05/2016, 9:48 AMFuture
of the value it returns. The code looks like this:
class Foo(private val executorCallback: ((GraphDatabaseService) -> Any?) -> Future<*>) { ... }
// instantiation site
private val executor: ExecutorService
private val db: GraphDatabaseService
executorCallback = { executor.submit { it(db) } }
My problem is that this is not type-safe. The future will always have the type of what the passed function will return but I can't express this. The best I can come up with is a wrapper function
@Suppress("UNCHECKED_CAST")
private fun <T> submit(f: (GraphDatabaseService) -> T): Future<T> {
return executorCallback(f) as Future<T>
}