M.K*_*.K. 4 types scala existential-type
我今天遇到了一种方法,该方法具有以下特征:
def foo() : Future[_] = { /* some code */ }
Run Code Online (Sandbox Code Playgroud)
我的问题是返回类型在这里是什么意思?这是否意味着此方法返回a Future并且我不在乎计算的类型是什么?或者是别的什么?
该Future[_]型只是为生存型占位符语法:
Future[X] forSome { type X }
Run Code Online (Sandbox Code Playgroud)
以便
def foo(): (Future[X] forSome { type X }) = { /* some code */ }
Run Code Online (Sandbox Code Playgroud)
意思是:foo返回一个Future值为未知类型的X。所以,你的解释
“此方法返回一个Future,我不在乎计算的类型是什么”
是正确的。